Need help AutoFilling a formula in a column

pawest

Board Regular
Joined
Jun 27, 2011
Messages
105
Hello,
I'm pulling data from a CSV file. The CSV file has a "Quantity" column that contains the absolute value of the quantity. I want to add a new "Qty" column and an if statement to say if certain criteria is met, make the value negative.

Here's what I have so far from the recorder... weirdly, this works on one spreadsheet and not another when referencing the same data... how can I make this better and more dynamic?

Code:
        Range("W1").Select
        ActiveCell.FormulaR1C1 = "Qty"
        ActiveCell.Offset(1, 0).Range("A1").Select
        ActiveCell.FormulaR1C1 = "=IF(RC[-24]=""B"",RC[-23],RC[-23]*-1)"
        Selection.AutoFill Destination:=ActiveCell.Range("A1:A" & finalRow)
 
Norie,

finalRow = Cells(Rows.count, 1).End(xlUp).Row

You were on to something. I was referencing W which doesn't contain the range of data, obviously just the value in W.

However, I switched it to: finalRow = Range("A1048576").End(xlUp).Row

...and it still caused the same error.

Can you show all your code? Are you calculating Finalrow for different sheets?
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,215,461
Messages
6,124,953
Members
449,198
Latest member
MhammadishaqKhan

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