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:

[TABLE="width: 240"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD] 500,000[/TD]
[TD] 263,000[/TD]
[/TR]
[TR]
[TD] 500,000[/TD]
[TD] 544,000[/TD]
[/TR]
[TR]
[TD] 500,000[/TD]
[TD] 383,000[/TD]
[/TR]
[TR]
[TD] 500,000[/TD]
[TD] 294,000[/TD]
[/TR]
[TR]
[TD] 650,000[/TD]
[TD] 563,000[/TD]
[/TR]
[TR]
[TD] 650,000[/TD]
[TD] 386,000[/TD]
[/TR]
[TR]
[TD] 1,000,000[/TD]
[TD] 980,224[/TD]
[/TR]
[TR]
[TD] 1,000,000[/TD]
[TD] 1,422,480[/TD]
[/TR]
[TR]
[TD] 500,000[/TD]
[TD] 462,000[/TD]
[/TR]
</tbody>[/TABLE]

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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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