Find Last Used Cell in Column and Autofill Data Down to Last Cell in Adjacent Column

mclark13

New Member
Joined
May 29, 2007
Messages
5
Hello, I have been working on trying to identify the solution to this for the past day with little success. Any assistance or guidance would be greatly appreciated.

I am copying data from one sheet (sheet A) and pasting into another sheet (sheet B). I can find the cell I need to paste the information into in Sheet B and am able to paste that information just fine. Once I paste the data to Column B in Sheet A, I find the last value in Column A and offset by 1 to go to the first empty cell as you can see in the code. At which time I add Today's date. What I am struggling with is autofilling the formula down to the last used cell in the adjacent column. I have found other posts that describe how to autofill down in a specific range (A1:A500 for example), but I am struggling with how to do it with a dynamic range.

Code:
Sub QBFindLastRow()
'Paste data into last open cell in column "B" for OrderID
'Add today's date to the next available empty cell in Column A and autofill down to last used cell in Column B
'Copy all the cells that were autofilled down and paste back as a value because the date needs to remain static since this is done each day

    Windows("1_b_MasterAllProductsUPCPID_Oracle_PC.xlsm").Activate
    Range("B1048576").End(xlUp).Offset(1).Select
    ActiveSheet.Paste
    
    Range("A1048576").End(xlUp).Offset(1).Select
    ActiveCell.FormulaR1C1 = "=TODAY()"
    ActiveCell.copy
   
End Sub

Thanks in advance for any ideas.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
The code below will autofill from B1 to the cell in Column B that is the same as the last cell in Column A

Code:
Sub CopyDown()
Range("B1").AutoFill Destination:=Range("B1:B" & Range("A" & Rows.Count).End(xlUp).Row)
End Sub
 
Upvote 0
Thank you Mark858 for such a quick reply. I may be missing it, but this is what I am trying to do. Each day I am adding to the list of data so the last used Cell in Column A will be dynamic as will the last used cell in Column B.

Code:
    Date           OrderID
1  07/16/2013      A12345
2  07/16/2013      B12345
3  07/16/2013      C12345
4  07/17/2013      D12345
5  Autofill        E12345
6  Autofill        F12345
7  Autofill        G12345
8  Autofill        H12345
9
10

Thank you again Mark858, much appreciated.
 
Upvote 0
Try
Code:
Sub CopyDown()
    Dim LRowB As Long, LRowA As Long
    With Sheets("SheetA")
        LRowB = .Range("B" & Rows.Count).End(xlUp).Row
        LRowA = .Range("A" & Rows.Count).End(xlUp).Row
        .Cells(LRowA, 1).AutoFill Destination:=.Range(.Cells(LRowA, 1), .Cells(LRowB, 1))
    End With
End Sub
 
Upvote 0
Mark858, thank you it works just like I need it to. Thank you again! As always, now I will try to understand what it is doing. Much appreciated Mark858. Have a wonderful day.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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