With...End with Suggestion

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,284
Office Version
  1. 365
Platform
  1. Windows
Good evening All,

Is this syntax wrong? I really dont understand why i am getting error.

Error - Invalid or Unqualified reference

Cells(fn, "B") = "LOAD SUMMARY:"

With .Range(.Cells(fn, "B"), .Cells(fn, "C"))
.Merge
.Font.Bold = True
.HorizontalAlignment = xlCenter
End With

Can any one suggest? I am trying r&d from last 1 n 1/2 hours.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
That would only work if it is within another With ... End With block that is holding a reference to a worksheet object. If not, then:
Code:
With Range(Cells(fn, "B"), Cells(fn, "C"))
.Merge
.Font.Bold = True
.HorizontalAlignment = xlCenter
End With
 
Upvote 0
depends what fn is.
also, you use With like this
Rich (BB code):
With Worksheets("HELLO")
    With Range(Cells(fn, "B"), Cells(fn, "C"))
        .Merge
    End With
End With

when you have a period (.) it means there is a 'parent' object which specifies which object it belongs to.
So, in your case, it was trying to find a explicitly stated parent object (worksheet) but you have not specified it.

It would also work without the period at the front if the code is in a worksheet module.
 
Last edited:
Upvote 0
REmove all the "."'s in your line:

With .Range(.Cells(fn, "B"), .Cells(fn, "C"))
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,853
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top