Macro to Copy to Last Row of Data

spyldbrat

Board Regular
Joined
May 5, 2002
Messages
211
Office Version
  1. 365
How do I edit this to copy the contents in cells P2 and Q2 the last row of data in both columns P & Q? I know where my problem below...I just don't know how to fix it.

Thanks

Range("p2").Select
ActiveCell.FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-13],Collector,3,FALSE),"" "")"
Range("p2").Select
Selection.AutoFill Destination:=Range("p2:p11")
Range("p2:p11").Select
Range("Q2").Select
ActiveCell.FormulaR1C1 = "=IF(ISBLANK(RC[-12]),"" "",VALUE(RC[-12]))"
Range("Q2").Select

Selection.AutoFill Destination:=Range("Q2:Q11")
Range("Q2:Q11").Select
Columns("Q:Q").Select
Selection.Copy
Columns("E:E").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Is there already data in Cols P & Q, that you're overwriting?
If not what col can be used to calculate the last row of data?
 
Upvote 0
Columns P and Q are empty with the exception of the header row on row 1. The above puts a formula in cells P2 and Q2 and I need those two formulas to copy down to the last line of data in my spreadsheet. The next empty column I have is R.
 
Upvote 0
One option is
Code:
    Dim UsdRws As Long
    
    UsdRws = Cells.Find("*", after:=Range("A1"), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

    Range("P2").FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-13],Collector,3,FALSE),"" "")"
    Range("Q2").FormulaR1C1 = "=IF(ISBLANK(RC[-12]),"" "",VALUE(RC[-12]))"
    Range("P2:Q" & UsdRws).FillDown
    Range("Q1:Q" & UsdRws).Copy
    Range("E1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Alternatively, if Col Q is simply to convert col E to values, try
Code:
    Dim UsdRws As Long
    
    UsdRws = Cells.Find("*", after:=Range("A1"), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

    Range("P2").FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-13],Collector,3,FALSE),"" "")"
    Range("P2:P" & UsdRws).FillDown
    With Range("E2:E" & UsdRws)
        .Value = .Value
    End With
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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