Fill Law Row Across Columns

quantmaven

New Member
Joined
May 16, 2018
Messages
11
Hi!
I have monthly time series from column A to AU. Every month I need to fill the last row. The code below works for ALL columns. How can I adapt this code so it does the same just from column A to AU? Thanks in advance!

Code:
Sub Fill_Lastrow_AcrossColumns()
Application.ScreenUpdating = False
Dim Ccol As Long
Dim c As String
Dim Dws As Worksheet
Set Dws = Sheets("DATA")
LastCol = Cells(7, Columns.Count).End(xlToLeft).Column
For Ccol = 2 To LastCol
    c = Replace(Split(Columns(Ccol).Address, "$")(1), ":", "")
    lrow = Sheets("DATA").Range(c & "65536").End(xlUp).Row
    Sheets("DATA").Range(c & lrow).Copy Destination:=Sheets("DATA").Range(c & lrow + 1)
Next
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi quantmaven,

You see the line starting with LastCol =... this line figures out the last column occupied with data. If you want to limit the processing to only columns A through AU, then you can comment this line out, and hard code the addresses of columns A = 1 and and U = 20 and Z = 26 and AU = ??? You can count them on your own.

Or you can change the For-Next loop counter to the value of column AU.

Hope this helps.
 
Upvote 0
How about
Code:
For Ccol = 2 To 47
    Lrow = Sheets("DATA").Cells(65536, c).End(xlUp).row
    Sheets("DATA").Cells(Lrow, c).Copy Destination:=Sheets("DATA").Cells(Lrow + 1, c)
Next
Or if all columns are the same length you can use
Code:
Sub Fill_Lastrow_AcrossColumns()
Application.ScreenUpdating = False
Dim Dws As Worksheet
Dim Lrow As Long
Set Dws = Sheets("DATA")
Lrow = Dws.Range("A" & Rows.Count).End(xlUp).row
Dws.Range("A" & Lrow).Resize(2, 47).FillDown
End Sub
 
Upvote 0
Phil & Fluff, thanks your suggestion worked! Last question: If I want to apply this code to multiple sheets except Sheet 1 and Sheet 2, how does the code fit inside this one? I'm all done after this. Thanks alot for your time I am greatful.

Sub Fill_Lastrow_AcrossColumns()
Application.ScreenUpdating = False
Dim Dws As Worksheet
Dim Lrow As Long
Set Dws = ActiveSheet
Lrow = Dws.Range("A" & Rows.Count).End(xlUp).Row
Dws.Range("A" & Lrow).Resize(2, 47).FillDown
End Sub

Sub Fill_Lastrow_AcrossColumns()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
' Exclude certain sheets
If ws.Name <> "Sheet1" Or ws.Name <> "Sheet2" Then
' Do your thing here
End If
Next ws
End Sub
 
Upvote 0
Simply replace ' Do your thing with
Code:
Lrow = Ws.Range("A" & Rows.Count).End(xlUp).row
Ws.Range("A" & Lrow).Resize(2, 47).FillDown
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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