VBA - Using .offset to select adjacent cells to merge

DCEXC

New Member
Joined
Oct 28, 2019
Messages
14
Hey people,

code segment will explain itself, everything works fine except method of range fails when trying to merge 2 adjacent cells.

fairly new to coding so bare with me

With QuotePreviewSheet.Range("D1000").End(xlUp).Offset(3, 0)

.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
.Font.Bold = False
.Font.name = "Lao UI"
.Font.Size = 10
.WrapText = True

'Adds in the scope name and formats
.Offset(-1, -1).Value = sh.name
.Offset(-1, -1).Font.Bold = True
.Offset(-1, -1).Font.Size = 12
.Offset(-1, -1).Font.name = "Lao UI"
.Range((.Offset(-1, -1)), Range((.Offset(-1, 0)))).Merge <-------- error line
'.WrapText = True

'Adds in the scope $$ and formats
.Offset(-1, 3).Value = sh.Range("F2").Value
.Offset(-1, 3).Font.Bold = True
.Offset(-1, 3).Font.Size = 12
.Offset(-1, 3).Font.name = "Lao UI"
'.WrapText = True

End With

is there a work around for selecting these 2 cells as it goes down the list each time to merge them??
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Maybe better to resize rather than offset. For example, to merge cells A1 and B1:

Range("A1").Resize(1,2).Merge

Keep in mind that the merger will remove all data in the merged cells except for that of the upper-left most cell being merged.
 
Upvote 0
With QuotePreviewSheet.Range("D1000").End(xlUp).Offset(3, 0)

Dim Rw As Integer
Rw = Range("D1000").End(xlUp).Offset(3, 0).Row

.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
.Font.Bold = False
.Font.name = "Lao UI"
.Font.Size = 10
.WrapText = True

'Adds in the scope name and formats
.Offset(-1, -1).Value = sh.name
.Offset(-1, -1).Font.Bold = True
.Offset(-1, -1).Font.Size = 12
.Offset(-1, -1).Font.name = "Lao UI"
'.Range((.Offset(-1, -1)), Range((.Offset(-1, 0)))).Merge
.Range("A" & Rw).Resize(Rw, 2).Merge
'.WrapText = True

'Adds in the scope $$ and formats
.Offset(-1, 3).Value = sh.Range("F2").Value
.Offset(-1, 3).Font.Bold = True
.Offset(-1, 3).Font.Size = 12
.Offset(-1, 3).Font.name = "Lao UI"
'.WrapText = True

End With

i did this but nothing happened
 
Upvote 0

Forum statistics

Threads
1,215,051
Messages
6,122,871
Members
449,097
Latest member
dbomb1414

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