Tech Support Forum banner
Status
Not open for further replies.
1 - 5 of 5 Posts

·
Registered
Joined
·
17 Posts
Discussion Starter · #1 · (Edited)
I have an IF statement i'd like to run as a macro, how do i do this?
=IF(A4=A3,B4+D3,B4)

I'd also like it to check the entire sheet. For example, to achieve this using the IF statement i'd have to type

=IF(A4=A3,B4+D3,B4) in the first cell, then these in the cells to follow.
=IF(A3=A2,B3+D2,B3)
=IF(A4=A3,B4+D3,B4)
=IF(A5=A4,B5+D4,B5)
=IF(A6=A5,B6+D5,B6)
=IF(A7=A6,B7+D6,B7)
=IF(A8=A7,B8+D7,B8)
=IF(A9=A8,B9+D8,B9)
=IF(A10=A9,B10+D9,B10)
=IF(A11=A10,B11+D10,B11)
=IF(A12=A11,B12+D11,B12)
=IF(A13=A12,B13+D12,B13)
=IF(A14=A13,B14+D13,B14)
=IF(A15=A14,B15+D14,B15)
=IF(A16=A15,B16+D15,B16)
=IF(A17=A16,B17+D16,B17)
=IF(A18=A17,B18+D17,B18)
=IF(A19=A18,B19+D18,B19)
=IF(A20=A19,B20+D19,B20)


data in the spreadsheet is this:

TASK VALUE Merged
ASSISTANCE 8 8
ASSISTANCE 6 14
ASSISTANCE 4 18
ASSISTANCE 11 29
ASSISTANCE 3 32
ASSISTANCE 12 44
ASSISTANCE 8 52
ASSISTANCE 10 62
ASSISTANCE 22 84
ASSISTANCE 23 107
ASSISTANCE 8 115
ASSISTANCE 12 127
ASSISTANCE 7 134
ASSISTANCE 10 144
Breaks 10 10
Breaks 15 25
Breaks 18 43
Breaks 7 50
Breaks 9 59
CLEAR DESK 20 20
Email 45 45
 

·
Premium Member
Joined
·
39,538 Posts
Hi

In VBA it's almost the same as you have posted...

But you must include an End If statement and your first If line will normally end in Then

Using your first line as an example
Code:
IF A4=(A3,B4+D3,B4) Then
'do something here
End If
However, if you intend testing many lines or cell values, then you might want to consider using a Select Case statement.

The Help files are pretty good on both If...Then and Select Case - search for 'looping through code'.
 
1 - 5 of 5 Posts
Status
Not open for further replies.
Top