Only Use the Number of Rows from A column to Copy to B,C,D columns??

mwalls33

New Member
Joined
Apr 25, 2018
Messages
19
Folks please help -
Trying to create a macro using "Record Macro" but I have a static fields on my range please see below: - Those are all 350... I want the last range to be the same range as the last range from A1 column, how do I do that? thank you!!!

Code:
Selection.Copy
    Sheets("Output").Select
    Range("A2").Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
    Range("B2").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = _
        "=VLOOKUP(RC[-1],[curentcontractor.xls]Data!C2:C3,2,FALSE)"
    Range("B2").Select
    Selection.AutoFill Destination:=Range("B2:B350")
    Range("B2:B350").Select
    Range("C2").Select
    ActiveCell.FormulaR1C1 = _
        "=VLOOKUP(RC[-2],[curentcontractor.xls]Data!C2:C8,6,FALSE)"
    Range("C2").Select
    Selection.AutoFill Destination:=Range("C2:C350")
    Range("C2:C350").Select
    Range("D2").Select
    ActiveCell.FormulaR1C1 = _
        "=VLOOKUP(RC[-3],[curentcontractor.xls]Data!C2:C8,4,FALSE)"
    Range("D2").Select
    Selection.AutoFill Destination:=Range("D2:D350")
    Range("D2:D350").Select
    Range("E2").Select
    ActiveCell.FormulaR1C1 = _
        "=VLOOKUP(RC[-4],[curentcontractor.xls]Data!C2:C11,10,FALSE)"
    Range("E2").Select
 
Last edited by a moderator:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
How about
Code:
   Dim Lr As Long
   Lr = Range("A" & Rows.Count).End(xlUp).Row
   Range("B2:B" & Lr).FormulaR1C1 = _
       "=VLOOKUP(RC[-1],[curentcontractor.xls]Data!C2:C3,2,FALSE)"
   Range("C2:C" & Lr).FormulaR1C1 = _
       "=VLOOKUP(RC[-2],[curentcontractor.xls]Data!C2:C8,6,FALSE)"
   Range("D2:D" & Lr).FormulaR1C1 = _
       "=VLOOKUP(RC[-3],[curentcontractor.xls]Data!C2:C8,4,FALSE)"
   Range("E2:E" & Lr).FormulaR1C1 = _
       "=VLOOKUP(RC[-4],[curentcontractor.xls]Data!C2:C11,10,FALSE)"
 
Upvote 0
How about
Code:
   Dim Lr As Long
   Lr = Range("A" & Rows.Count).End(xlUp).Row
   Range("B2:B" & Lr).FormulaR1C1 = _
       "=VLOOKUP(RC[-1],[curentcontractor.xls]Data!C2:C3,2,FALSE)"
   Range("C2:C" & Lr).FormulaR1C1 = _
       "=VLOOKUP(RC[-2],[curentcontractor.xls]Data!C2:C8,6,FALSE)"
   Range("D2:D" & Lr).FormulaR1C1 = _
       "=VLOOKUP(RC[-3],[curentcontractor.xls]Data!C2:C8,4,FALSE)"
   Range("E2:E" & Lr).FormulaR1C1 = _
       "=VLOOKUP(RC[-4],[curentcontractor.xls]Data!C2:C11,10,FALSE)"

OMG! works like a charm! thank you sooo sooo much!!!
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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