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.
 

Some videos you may like

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.

brian.wethington

Well-known Member
Joined
Jul 20, 2006
Messages
1,739
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
 

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
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
 

Karleen26

New Member
Joined
Jul 28, 2007
Messages
5
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?
 

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
My posted code will also do this in one of the data cells or in a non-data cell.
 

brian.wethington

Well-known Member
Joined
Jul 20, 2006
Messages
1,739
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,320
Messages
5,600,946
Members
414,417
Latest member
Nobu

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
Top