Copy column to Another sheet...incrementally increasing the column every run of the vba

chiswickbridge

Board Regular
Joined
Feb 2, 2013
Messages
127
Hi,

I have dynamic data on one sheet in a Column E2 to E101. This is updated on a daily basis.

Need a VBA to copy this column and save this data for future use, on a different sheet, Starting Column is AA.

AA1 will contain the date and AA2 to AA101 will have the data correspondingly.

Next day the saved data will use column AB and so forth...

Thank you in advance...
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try:
VBA Code:
Sub CopyCol()
    Application.ScreenUpdating = False
    Dim LastRow As Long, lCol As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    lCol = Cells(1, Columns.Count).End(xlToLeft).Column
    If lCol < 27 Then
        Range("AA1") = Date
        Range("E2:E" & LastRow).Copy Range("AA2")
    ElseIf lCol >= 27 Then
        lCol = Cells(1, Columns.Count).End(xlToLeft).Offset(0, 1).Column
        Cells(1, lCol) = Date
        Range("E2:E" & LastRow).Copy Cells(2, lCol)
    End If
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Change the sheet names (in red) to suit your needs.
Rich (BB code):
Sub CopyCol()
    Application.ScreenUpdating = False
    Dim LastRow As Long, lCol As Long, srcWS As Worksheet, desWS As Worksheet
    Set srcWS = Sheets("Name1")
    setr desWS = Sheets("Name2")
    LastRow = srcWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    With desWS
        lCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
        If lCol < 27 Then
            .Range("AA1") = Date
            Range("E2:E" & LastRow).Copy .Range("AA2")
        ElseIf lCol >= 27 Then
            lCol = .Cells(1, .Columns.Count).End(xlToLeft).Offset(0, 1).Column
            .Cells(1, lCol) = Date
            Range("E2:E" & LastRow).Copy .Cells(2, lCol)
        End If
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
hi, mumps it's very strange in post#4 if the code works it supposes showing error it should set not setr in this line
VBA Code:
    setr desWS = Sheets("Name2")
and i would ask you about this line
Code:
LastRow = srcWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
what look for in last row i always see * what means and when use it this
 
Upvote 0
@abdelfattah
You are correct. "setr" should be "Set". That was a typo on my part.

The asterisk (*) is a wild card to find any data that is contained in the last used row. You use this line of code to return the row number of the last used row.
 
Upvote 0
YESSSSS...Works fine...You made my week-end....I have planned to have a a small BBQ tomorrow...Will raise my glass to u...
 
Upvote 0

Forum statistics

Threads
1,214,960
Messages
6,122,479
Members
449,088
Latest member
Melvetica

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