PDA

View Full Version : Solved: Add If Statment to w/ Array to Loop



YellowLabPro
05-23-2007, 06:56 AM
In my loop I would like to place an If statment that will utilize an Array.
I do something similar w/ a formula in Excel, but this is new to me by way of placing it inside of code.
Reference formula in Excel: =IF(OR(ISNUMBER(MATCH(AD5,{"SURF","SKATE","SNOW","WAKE"})))
If any values match these terms, Surf, Skate, Snow, Wake are in column E, then instead of using this line: .Cells(LRowt, "J").Value = Wss.Cells(i, "E").Value ' Item
use this line: .Cells(LRowt, "J").Value = Wss.Cells(i, "F").Value ' Item or use an offset of 1 column

Existing Loop:

For i = 2 To Wss.Cells(Rows.Count, "I").End(xlUp).Row
LRowt = Wst.Cells(Rows.Count, "I").End(xlUp).Row + 1
If Val(Cells(i, "j")) > 0 Then
With Wst
.Cells(LRowt, "AC").Value = Wss.Cells(i, "j").Value ' Qty = col. AC/29
.Cells(LRowt, "H").Value = Wss.Cells(i, "A").Value ' Company
.Cells(LRowt, "I").Value = Wss.Cells(i, "C").Value ' Item Name
.Cells(LRowt, "M").Value = Wss.Cells(i, "D").Value ' Color
.Cells(LRowt, "J").Value = Wss.Cells(i, "E").Value ' Item
.Cells(LRowt, "Z").Value = Wss.Cells(i, "G").Value ' Cost
.Cells(LRowt, "N").Value = Wss.Cells(i, "H").Value ' Size

End With
End If
Next i


Thanks for looking over,

Doug

mvidas
05-23-2007, 07:18 AM
Hi Doug,

Which cell could have one of those values in it? Wss.Cells(i, "E") or Wst.Cells(LRowt, "AD") ?

Matt

mvidas
05-23-2007, 07:29 AM
Ok, assuming you mean wss.cells(i,"e"):'put this above/outside your Loop
Dim vArray() As Variant
vArray = Array("Surf", "Skate", "Snow", "Wake")

'replace the commented line with the one following it:
' .Cells(LRowt, "J").Value = Wss.Cells(i, "E").Value ' Item
.Cells(LRowt, "J").Value = Wss.Cells(i, "E").Offset(0, _
IIf(Not IsError(Application.Match(Wss.Cells(i, "E").Value, _
vArray, 0)), 1, 0)).Value ' ItemMatt

YellowLabPro
05-23-2007, 07:32 AM
Sorry for the no response,
I am not getting any email notices and I have to keep refreshing to see if there is a reply....
I will test now- and yes you were correct in the (i,"e")

YellowLabPro
05-23-2007, 07:38 AM
Matt,
Beauty! Thanks