[TABLE="width: 783"]
<TBODY>[TR]
[TD="class: xl24, width: 1044, bgcolor: transparent"][TABLE="width: 475"]
<COLGROUP><COL style="WIDTH: 475pt; mso-width-source: userset; mso-width-alt: 23149" width=633><TBODY>[TR]
[TD="class: xl25, width: 633, bgcolor: transparent"]I want to replace a nested IF worksheet function to allow expansion of my options. I couldn't puzzle out an IF statement that worked, but managed to cobble together a Select Case statement which does the job. The problem is that it takes over 50 seconds to run, compared to about 0.2 seconds for the IF function. I know a Vlookup function is a good alternative (in fact faster than IF), but I'm hoping someone can advise why I'm getting such a time difference between two processes doing essentially the same job?
[TABLE="width: 475"]
<COLGROUP><COL style="WIDTH: 475pt; mso-width-source: userset; mso-width-alt: 23149" width=633><TBODY>[TR]
[TD="class: xl25, width: 633, bgcolor: transparent"]The object is to enter a number in Column AA, based on information in the corresponding row in Column F. There are usually about 1000 rows of data. I'm enclosing the existing code and the slow alternative. Any help would be appreciated.[/TD]
[/TR]
</TBODY>[/TABLE]
[/TD]
[/TR]
</TBODY>[/TABLE]
[/TD]
[/TR]
[TR]
[TD="class: xl24, width: 1044, bgcolor: transparent"]Steve
[/TD]
[/TR]
</TBODY>[/TABLE]
<TBODY>[TR]
[TD="class: xl24, width: 1044, bgcolor: transparent"][TABLE="width: 475"]
<COLGROUP><COL style="WIDTH: 475pt; mso-width-source: userset; mso-width-alt: 23149" width=633><TBODY>[TR]
[TD="class: xl25, width: 633, bgcolor: transparent"]I want to replace a nested IF worksheet function to allow expansion of my options. I couldn't puzzle out an IF statement that worked, but managed to cobble together a Select Case statement which does the job. The problem is that it takes over 50 seconds to run, compared to about 0.2 seconds for the IF function. I know a Vlookup function is a good alternative (in fact faster than IF), but I'm hoping someone can advise why I'm getting such a time difference between two processes doing essentially the same job?
[TABLE="width: 475"]
<COLGROUP><COL style="WIDTH: 475pt; mso-width-source: userset; mso-width-alt: 23149" width=633><TBODY>[TR]
[TD="class: xl25, width: 633, bgcolor: transparent"]The object is to enter a number in Column AA, based on information in the corresponding row in Column F. There are usually about 1000 rows of data. I'm enclosing the existing code and the slow alternative. Any help would be appreciated.[/TD]
[/TR]
</TBODY>[/TABLE]
[/TD]
[/TR]
</TBODY>[/TABLE]
[/TD]
[/TR]
[TR]
[TD="class: xl24, width: 1044, bgcolor: transparent"]Steve
Code:
Sub LKup7()
t = Timer
With Range(Cells(2, "a"), Cells(Rows.Count, "a").End(xlUp)).Offset(, 25)
.FormulaR1C1 = "=if(or(RC6=""QLD"",RC6=""SA"",RC6=""Int"",RC6=""""),-1,if(RC6=""NT"",-8,if(RC6=""ACT"",-2,if(RC6=""NZ"",-2,IF(RC6=""WA"",-3,If(RC6=""TAS"",-8,""""))))))"
.Value = .Value 'comment out to leave formulae present
End With
MsgBox Timer - t
End Sub
Code:
Sub Lkup6()
t = Timer
Dim x As Long
For x = 2 To Range("A" & Rows.Count).End(xlUp).Row
Select Case Range("f" & x).Value
Case "Vic", "Nsw"
Range("aa" & x).Formula = "0"
Case "Nz", "Act"
Range("aa" & x).Formula = "2"
Case "Qld", "SA", "Int", """"
Range("aa" & x).Formula = "-1"
Case "wA"
Range("aa" & x).Formula = "-3"
Case "Tas", "Nt"
Range("aa" & x).Formula = "-8"
End Select
Next
MsgBox Timer - t
End Sub
[/TR]
</TBODY>[/TABLE]
Last edited: