Offset Merged Cells

JasonC-VBA

New Member
Joined
Aug 30, 2011
Messages
21
How do you offset the address of merged cells in VBA?
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
Example:
StartingAddress = G14:G16
<o:p> </o:p>
And I want NewAddress = F14:F16
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
I'm sure there is better method. I can only think of

Code:
Sub Test()
 Range("G14:G16").Offset(0, -1).Resize(3, 1)
End Sub

Biz
 
Upvote 0
I think the offset the address of first of the merged cells will be enough, try this:

Code:
Range("G14").Offset(0, -1).Resize(3, 1)
outcome will be the same as obtained with Biz's method
 
Upvote 0
Thought of new way instead hard coding 3

Code:
Sub Test()
Dim myRange As Range
'   Set your range here
    Set myRange = Range("G14:G16")
  Range("G14:G16").Offset(0, -1).Resize(myRange.Cells.Count, 1)
End Sub

Alternatively using P.Holko

Code:
Sub Test()
Dim myRange As Range
'   Set your range here
    Set myRange = Range("G14:G16")
  nge("G14").Offset(0, -1).Resize(myRange.Cells.Count, 1)
End Sub

Biz
 
Upvote 0
Without knowing in advance that there are 3 cells merged together...

Code:
Dim MA As Range, NewAddress As String
.....
.....
Set MA = Range("G14").MergeArea
NewAddress = MA.Offset(, -1).Resize(MA.Rows.Count).Address
This will work if G14 is not part of a merged area as well (assuming that would be meaningful inside the overall program).
 
Upvote 0
Without knowing in advance that there are 3 cells merged together...

Code:
Dim MA As Range, NewAddress As String
.....
.....
Set MA = Range("G14").MergeArea
NewAddress = MA.Offset(, -1).Resize(MA.Rows.Count).Address
This will work if G14 is not part of a merged area as well (assuming that would be meaningful inside the overall program).

Hi Rick,

Thanks for pointing out Range.MergeArea Property. I learnt something new thank you mate.

Biz
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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