Moving Column Headings

seendcleeve

New Member
Joined
Mar 26, 2004
Messages
43
I have a spreadsheet that came from Access

It contains Data in 56 Columns each down to Row 1856

Is it Possible to insert a New Column next to every Column containing the data

And then Copy the Column Heading Where the Data is held into this new Column Down to row 1856 for ever new Column :eek:
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
This?:

Code:
Sub InsertCol()

Dim icol As Long
Dim irow As Long
Dim strColHeader As String

For icol = 56 To 1 Step -1
    strColHeader = Cells(1, icol)
    Cells(1, icol + 1).EntireColumn.Insert
        For irow = 2 To 1856
            Cells(irow, icol + 1) = strColHeader
        Next
Next

End Sub
 
Upvote 0
Hi, guys,
instead of this loop
Code:
        For irow = 2 To 1856 
            Cells(irow, icol + 1) = strColHeader 
        Next
you can code at once
Code:
Range(Cells(1, icol), Cells(1856, icol)) = strColHeader

if 1856 can be variable
Code:
Dim LR As Long, LC As Long
LR = Cells.Find("*", [A1], xlFormulas, xlPart, xlByRows, xlPrevious, False, False).Row
Range(Cells(1, icol), Cells(LR, icol)) = strColHeader

kind regards,
Erik
 
Upvote 0

Forum statistics

Threads
1,219,162
Messages
6,146,660
Members
450,706
Latest member
LGVBPP

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