macros and cell merge

Karleen26

New Member
Joined
Jul 28, 2007
Messages
5
Hi I am trying to make a macro that will merge the same columns always but in different rows.

I know how to make an easy marco, but everytime I make the marco, it keeps going back to the same rows I made it in and in the current row.


Any help would be great.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
To do this over many rows

Code:
Sub MergingCol()

For x = 6 to 50
    Range(Cells(x, "A"), Cells(x, "E")).Merge
Next

End Sub
This would merge rows 6 to 50 Columns A through E

but I also would like to warn you of merging cells. It can cause issues with VBA as well some some other oddities as well.

~Edit-Fixed a typo
 
Upvote 0
Which columns?

This will use the current cells row and in the current selection add the values from Column 1 and Column 2 of that row to the current cell as a cancantanated string!


Sub cantCells()
'Sheet module code, like: Sheet1!
Dim lngMyRow&

lngMyRow = Selection.Row

Selection.Value = ActiveSheet.Cells(lngMyRow, 1).Value & " " & ActiveSheet.Cells(lngMyRow, 2).Value
End Sub
 
Upvote 0
hmmm,

OK let me explain this better..

in rows 1 and 2, I want to merge cells A1 and A2 together then D1 and D2 and then G1 and G2

It's always the same columns but in different rows.

Does this help? Or will the above post still work?
 
Upvote 0
My posted code will also do this in one of the data cells or in a non-data cell.
 
Upvote 0
There would only be a slight modification as far as I can tell

Code:
Sub MergingCol() 

For x = 1 to 210 Step 3
    Range(Cells(1, x), Cells(2, x)).Merge 
Next 

End Sub

I am assuming you are always merging rows 1 and 2, This will skip 3 columns between each.
 
Upvote 0

Forum statistics

Threads
1,211,696
Messages
6,103,354
Members
447,861
Latest member
LllopezXC

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