VBA for IF statement across Range

Small Paul

Board Regular
Joined
Jun 28, 2018
Messages
118
Hi All

I am trying to use an IF statement in a VBA and am struggling!
A section of the range (in columns E & F) is below:

500,000 263,000
500,000 544,000
500,000 383,000
500,000 294,000
650,000 563,000
650,000 386,000
1,000,000 980,224
1,000,000 1,422,480
500,000 462,000

<colgroup><col><col></colgroup><tbody>
</tbody>

I need to show the difference, for each row, in column H. Easy as a one off : =if(E4>0,E4-F4,"") and copy down!

Code:
    Range("H4:H2533").Select    ActiveCell.FormulaR1C1 = "=if(E4>0,E4-F4,"""

Can anybody please advise?
Many thanks
Small Paul.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Like this maybe, change Sheet1 to your sheet name:

Code:
With Sheets("Sheet1")
    lr = .Range("E" & .Rows.Count).End(xlUp).Row
    If lr > 3 Then .Range("H4:H" & lr).FormulaR1C1 = "=IF(RC[-3]>0,RC[-3]-RC[-2],"""")"
End With
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,731
Members
448,987
Latest member
marion_davis

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