Code to Merge across numerous columns

Miche25

New Member
Joined
Jan 5, 2016
Messages
24
I have the following code, however I need "Customer Name" to merge and centre across columns B to J instead of appearing in just column B. How do I change the below code to reflect this?

Range("B" & Range("B" & Rows.Count).End(xlUp).Row + 3).Select
ActiveCell.FormulaR1C1 = "Customer Name"
Selection.Font.Bold = False
With Selection.Font
.Name = "Arial"
.Size = 18
End With
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
I would highly recommend using the "Center Across Selection" format option instead of merging the cells. It gives the same visual effect that merging across a row does, but without all the issues that merged cells cause (merged cells are very problematic for things like sorting and VBA, and should really be avoided whenever possible).

See: http://blog.contextures.com/archives/2014/04/10/center-headings-without-merging-cells/

If you use the Macro Recorder, you can get the code for that, i.e.
Code:
    Range("B4:J4").HorizontalAlignment = xlCenterAcrossSelection
 
Upvote 0
Thanks, the row can differ and is not static. how would I change your code to make it dynamic instead of row 4?
 
Upvote 0
how would I change your code to make it dynamic instead of row 4?
It depends on your answer to the following question:
What is the logic for dynamically determine which row to apply this to?
In another words, how do we locate this row you want to do this to?
 
Upvote 0

Forum statistics

Threads
1,215,982
Messages
6,128,104
Members
449,421
Latest member
AussieHobbo

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