Copying formula to the last active row

NoxGalleon106

New Member
Joined
Oct 15, 2016
Messages
29
Hi,

I have a formula in B2 that i want to drag up to the last row that has a value in column C.

Formula is:
= if(D2=“BOAUSD”, “NY to advise”, IF (D2= “TDTOR”, “Toronto to advise”, “London to advise”))

When I drag to the next row, the cell should change to D4,D5 etc.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
it does for me, do you have filters in place?
 
Upvote 0
it does for me, do you have filters in place?

Hi, there are no filters.can you help me with the correct VBA code to execute the scenario I have described? The formula is in B2 and should be drag up to the last row where there is value in column C.
 
Upvote 0
when you said drag I assumed you would do it manually

Code:
 Sub Macro1()
    Dim LastRow As Long
    LastRow = ActiveSheet.Range("C100000").End(xlUp).Row
    Range("B2").FormulaR1C1 = _
        "=IF(RC[2]=""BOAUSD"",""NY to advise"",IF(RC[2]=""TDTOR"",""Toronto to advise"",""London to advise""))"
    Range("B2").Select
    Selection.AutoFill Destination:=Range("B2:B" & LastRow), Type:=xlFillDefault
    Range("B2:B" & LastRow).Select
End Sub
 
Upvote 0
@NoxGalleon106, you apply the formula directly to the range without filling/copying (Excel is intelligent enough to increment the rows).

Code:
Sub FillFormula()
Range("B2:B" & Range("C" & Rows.Count).End(xlUp).Row).Formula = "=IF(D2=""BOAUSD2"", ""NY to advise"", IF(D2= ""TDTOR"", ""Toronto to advise"", ""London to advise""))"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,543
Members
449,089
Latest member
davidcom

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