View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Leo Heuser[_3_] Leo Heuser[_3_] is offline
external usenet poster
 
Posts: 109
Default Need help creating a case statement

Try this one (untested):

For Each Cell In Range("D3:AJ19")
IF [D$1] = [$B3] And [D$1] <= [$C3] And _
[E24] = [AK1] And Cell.Offset(0, 33+OffsetVal) = 2 Then

For j = StartNum To StartNum+6
Cell.Offset(0, j).Value = [AK$1]
Next j

StartNum = StartNum + 7
OffsetVal = OffsetVal + 1
End if
Next Cell

I take it, that [AL$1] is supposed to be [AK$1]

--
Best Regards
Leo Heuser

Followup to newsgroup only please.

"hotherps " skrev i en meddelelse
...
I'm sure there is a better way to do this, but this is all I can come up
with. If you notice below the only thing different between the two
groups of code is: Cell.Offset(0,33) and Cell.Offset(0,34)
And j = 0 to 6 changes to k = 7 to 13


Is there a way to use a case statement so I do not have to keep writing
the code over and over.

I need to continue incrementing the offset, and the for variable quite
a few more times.

For Each Cell In Range("D3:AJ19")
If [D$1] = [$B3] And [D$1] <= [$C3] And _
[E24] = [AK1] And Cell.Offset(0, 33) = 2 Then
For j = 0 To 6
Cell.Offset(0, j).Value = [AK$1]
Next j


If [D$1] = [$B3] And [D$1] <= [$C3] And _
[E24] = [AK1] And Cell.Offset(0, 34) = 2 Then
For k = 7 To 13
Cell.Offset(0, k).Value = [AL$1]
Next k

Thanks


---
Message posted from http://www.ExcelForum.com/