Fill more columns cell until another columns last cell

David0606

New Member
Joined
Oct 20, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi,

Please help me to find the code what I am looking for..Tried a lot of variation but I couldn't make the perfect code.

So the situation is I made a riport every day and I have to copy the data from another file under the previous days lines. This part is working. After that I have to fill cells in U:AM columns which are contain formulas. I want to fill that columns with the formulas from the previous days, until the last data in A or B or any columns until T(because every columns have data from A-T).
This is how my codes looks like:

Dim lastRow As String
lastRow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row + 1
Range("A" & lastRow).Select
Selection.PasteSpecial
Application.CutCopyMode = False
Range("U" & lastRow - 1).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.AutoFill Destination:=

Here I selected the cells with formulas which I want to fill and I am stucked at what destination should I use to fill only until the last used cell of A-T.

Many thanks,
David
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Welcome to the Board!

How about something like this:
VBA Code:
Sub MyCopyFormulasDown()

    Dim lrB As Long
    Dim lrU As Long
    
'   Find last rows in column B and U with data
    lrB = Cells(Rows.Count, "B").End(xlUp).Row
    lrU = Cells(Rows.Count, "U").End(xlUp).Row
    
'   Check to see if need to copy formulas in U:AM down
    If lrB > lrU Then
'       Copy formulas in U:AM down to last row
        Range(Cells(lrU, "U"), Cells(lrU, "AM")).Copy Range(Cells(lrU + 1, "U"), Cells(lrB, "U"))
    End If

End Sub
 
Upvote 0
Solution
Thank you for the warm welcome!

Yess, it is working well!

Thank you for your help!
 
Upvote 0
You are welcome.
Glad I was able to help!
:)
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,210
Members
453,023
Latest member
alabaz

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