MergeCells = True - Range Reference

Apple1

Board Regular
Joined
Jan 18, 2015
Messages
121
Using Excel 2013.

I am puzzled. Why does the 1st line of code work but not the 2nd? Thank you.

ThisWorkbook.Sheets("Table 1").Range(Cells(1, 1).Address & ":" & Cells(1, 3).Address).MergeCells = True




ThisWorkbook.Sheets("Table 1").Range("A1:C1").MergeCells = True

 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Using Excel 2013.

I am puzzled. Why does the 1st line of code work but not the 2nd? Thank you.

ThisWorkbook.Sheets("Table 1").Range(Cells(1, 1).Address & ":" & Cells(1, 3).Address).MergeCells = True




ThisWorkbook.Sheets("Table 1").Range("A1:C1").MergeCells = True


Initially I was in two minds, pass this up or ask 'what do you mean by your question?'.
It is unfortunate that you chose that shade of green in your post. At first I though it was your signature.

As you cannot edit it, I've changed the colour in my quote.
While I can't answer maybe the re-colour may get someone who is able once they can read the text.
 
Upvote 0
Why do you say the second lie doesn't work?
It works perfectly well for me.
 
Upvote 0
Personally I looked at this earlier today and I could understand it if it was the first code giving the error rather than the 2nd depending on what was the active sheet at the time.
 
Upvote 0
@MARK858
Good point. That 1st code would be better of written like
Code:
With ThisWorkbook.Sheets("Table 1")
    .Range(.Cells(1, 1).Address & ":" & .Cells(1, 3).Address).MergeCells = True
End With
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,985
Members
452,540
Latest member
haasro02

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