Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
ELSEIF for multiple if ??
I have this code that worked fine. Just needed to add a few more
conditions. It was suggested that I use the code (2nd one below) with the elseif statements, however that didnt quite work for me. I broke the elseif statements down and ran them individually inside the same code (placed a ' infront of the other lines and changed them to If statements) and was successful. Any suggestions....? /////////////////////ORIGINAL CODE//////////////// Sub macro200() Dim c As Range Dim rng As Range Dim ws As Worksheet Set ws = Worksheets("Sheet1") Set rng = ws.Range("h3:h" & ws.Cells(ws.Rows.Count, "h").End(xlUp).Row) For Each c In rng If c.Value = Range("ao2").Value Then c.Offset(0, 1).Value = c.Offset(0, 33).Value End If Next c End Sub //////////SUGGESTED CODE /////////////// Sub macro200() Dim c As Range Dim rng As Range Dim ws As Worksheet Set ws = Worksheets("Sheet1") Set rng = ws.Range("h3:h" & ws.Cells(ws.Rows.Count, "h").End(xlUp).Row) For Each c In rng If c.Value = Range("ao2").Value Then c.Offset(0, 1).Value = c.Offset(0, 33).Value ElseIf c.Value = Range("ap2").Value Then c.Offset(0, 2).Value = c.Offset(0, 34).Value ElseIf c.Value = Range("aq2").Value Then c.Offset(0, 3).Value = c.Offset(0, 35).Value End If Next c End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
elseif | Excel Programming | |||
IF..Then..ELSE.. ELSEIF | Excel Programming | |||
If, ElseIf | Excel Programming | |||
ElseIf | Excel Programming | |||
If...Elseif...End If | Excel Programming |