?
Solved

Problem to the message

Posted on 2016-07-28
13
Medium Priority
?
80 Views
Last Modified: 2016-07-28
Hi,
It is strange that, it is showing the message by 'Msgbox' below, while the 2nd and 3rd Debug.print is not showing anything below.
        With Worksheets("Main Sheet").Range(copyRange)
            Set c = .Find(Month0, LookIn:=xlValues)
            Debug.Print Month0
            If Not c Is Nothing Then
            Debug.Print "xc" & CStr(c.Row)
            Debug.Print Format(Worksheets("Main Sheet").Cells(c.Row, 8).Value, "yyyy/MM") & "mm" & Format(Worksheets("Month Status").Cells(i, 4).Value, "yyyy/MM")
            If Trim(Format(Worksheets("Main Sheet").Cells(c.Row, 8).Value, "yyyy/MM")) <> "" Then
            If Format(Worksheets("Main Sheet").Cells(c.Row, 8).Value, "yyyy/MM") = Format(Worksheets("Month Status").Cells(i, 4).Value, "yyyy/MM") Then
                MsgBox "You cannot copy record of a closed month.", vbExclamation, "Month is closed!"
                Exit Sub
                
            End If
            End If
            End If
    
        End With

Open in new window

0
Comment
Question by:HuaMinChen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 41732509
Put a Breakpoint (F9) on line 1. When the code breaks there, press F8 to step through the code until the message is displayed. That should show you which lines are being executed.

(I suspect that you have some similar code somewhere else in the procedure)
0
 
LVL 11

Author Comment

by:HuaMinChen
ID: 41732514
I did search the whole workbook and there is no similar Msgbox line in other places.
I re-try and really the above Msgbox line is being displayed while 2nd and 3rd debug line is not showing anything.
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 41732535
Skip the first print (e.g. comment it out), and then see if that changes the output.
are you certain that the first print displays something?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Author Comment

by:HuaMinChen
ID: 41732538
Yes, 1st debug line is printing out one line, while 2nd and 3rd debug line is not.

I comment out 1st debug line then I've got the same problem again.

I'm using Excel 2010.
0
 
LVL 32

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41732556
Open your workbook, open VBA editor --. Press Ctrl+G to open Immediate Window and in there just type Debug.Print "xc" and press Enter.

Is xc returned in the immediate window?
0
 
LVL 11

Author Comment

by:HuaMinChen
ID: 41732562
Many thanks to all.
I get
5m.pngdue to last line below
   Dim copyRange As Range, pasteRange As Range
   Dim Message0 As String
   'On Error Resume Next
...
        With Worksheets("Main Sheet").Range(copyRange)

Open in new window


as I've just commented out 3rd line in above.
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 41732566
??? the Debug output is not corresponding to code ...
0
 
LVL 11

Author Comment

by:HuaMinChen
ID: 41732568
Since the resume line is bypassing the error encountered, before this.
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 41732807
The debug output we see in the Immediate window is from prior runs (with On Error Resume Next active)?
If so, we'll ignore that.

The With references to a specific worksheet, to check for the range selected by the user on prompt. Why? The Range object should already have all required references.
0
 
LVL 11

Author Comment

by:HuaMinChen
ID: 41732817
Yes, before this, that resume line is on. Please now leave my original query.

How to resolve the current problem as shown?
0
 
LVL 70

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 41732940
Just use the Range object as-is. With Worksheets("Main Sheet").Range(copyRange) is With copyRange then.
0
 
LVL 11

Author Comment

by:HuaMinChen
ID: 41733237
Yes, the error is due to such Range line, while copyRange is having

$20:$20

inside.
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 41733837
I've tested it with an empty workbook, and I'm correct. Do as suggested in https:#a41732940.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question