Problem to the message

HuaMin Chen
HuaMin Chen used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
GrahamSkanRetired
Top Expert 2012

Commented:
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)
HuaMin ChenProblem resolver

Author

Commented:
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.
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
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?
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

HuaMin ChenProblem resolver

Author

Commented:
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.
Subodh Tiwari (Neeraj)Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015

Commented:
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?
HuaMin ChenProblem resolver

Author

Commented:
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.
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
??? the Debug output is not corresponding to code ...
HuaMin ChenProblem resolver

Author

Commented:
Since the resume line is bypassing the error encountered, before this.
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
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.
HuaMin ChenProblem resolver

Author

Commented:
Yes, before this, that resume line is on. Please now leave my original query.

How to resolve the current problem as shown?
"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
Commented:
Just use the Range object as-is. With Worksheets("Main Sheet").Range(copyRange) is With copyRange then.
HuaMin ChenProblem resolver

Author

Commented:
Yes, the error is due to such Range line, while copyRange is having

$20:$20

inside.
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
I've tested it with an empty workbook, and I'm correct. Do as suggested in https:#a41732940.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial