Formatting with VBA

jose001

Board Regular
Joined
Mar 27, 2006
Messages
103
Hey everyone,

Not sure if this is a complicated problem or not but it is well out of my reach. I have a spreadsheet with data in the first two rows A-H. There may also be more data though in columns D&E. I want to put some code into my VBA form which will check what is the last row with data in it (columns D&E), select cells in column A (from A2 down to that row with data) and merge cells. Its just some further formatting whihc I would like to add to tidy things up but its proving a bit tricky for me. Any ideas

Thanks guys
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
From Cell A2 down to the last cell in A which has data in the row, the data will be in dolumns D&E though
 
Upvote 0
Try this:
Code:
Sub MergeCells()
Dim LimitD As Long
Dim LimitE As Long
LimitD = Cells(Rows.Count, 4).End(xlUp).Row
LimitE = Cells(Rows.Count, 5).End(xlUp).Row
If LimitE > LimitD Then LimitD = LimitE
Range("A2:A" & LimitD).MergeCells = True
End Sub
 
Upvote 0
Thats fantastic Lewiy, thanks very much. Can you recommend a good book on VBA, the learning curve is very steep with trial and error :) but lots of fun though!!
 
Upvote 0
Thats fantastic Lewiy, thanks very much. Can you recommend a good book on VBA, the learning curve is very steep with trial and error :) but lots of fun though!!
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,845
Members
449,051
Latest member
excelquestion515

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