"Case" Problem
You want to use multiple case statements. This will make your code more
efficient as it needs to make fewer comparison. Also when ordering your case
statement make sure to put the most likely situations near the top... So
something like this...
If dblSubTotal 0 Then
Select Case strSalaryOrHour
Case "S" 'S is more likely than H
Select Case lngPenRow
Case Is 0 '0 more likely than 0
Set rngWorkCell = Cells(lngPenRow, 20)
Case 0
lngPenRow = 1
Set rngWorkCell = Cells(lngPenRow, 20)
End Select
Case "H"
Select Case lngPn2Row
Case Is 0
Set rngWorkCell = Cells(lngPn2Row, 21)
Case 0
lngPn2Row = 1
Set rngWorkCell = Cells(lngPn2Row, 21)
End Select
End Select
rngWorkCell.Select
rngWorkCell.Value = dblSubTotal
End If
--
HTH...
Jim Thomlinson
"Dave Birley" wrote:
The trouble with having programmed for a long time in one language is that
your thought system for design constantly works along the same routes. Here
is a simple Case statement...
If dblSubTotal 0 Then
Select Case strSalaryOrHour
Case "S" And lngPenRow 0
Set rngWorkCell = Cells(lngPenRow, 20)
Case "S" And lngPenRow = 0
lngPenRow = 1
Set rngWorkCell = Cells(lngPenRow, 20)
Case "H" And lngPn2Row 0
Set rngWorkCell = Cells(lngPn2Row, 21)
Case "H" And lngPn2Row = 0
lngPn2Row = 1
Set rngWorkCell = Cells(lngPn2Row, 21)
End Select
rngWorkCell.Select
rngWorkCell.Value = dblSubTotal
End If
Where everything is Dimmed, and lngPenRow (or lngPn2Row) will have received
a value in the If construct immediately preceding this. Unfortunately each
Case is based on a compound test, where one part is Character and one part is
Numeric, and (I hate to confess this in public) I did read the Help file on
Case, so I know why that dog don't hunt.
So how must I re-structure this to get to where I'm trying to go
(rngWorkCell.Value = dblSubTotal)?
--
Dave
Temping with Staffmark
in Rock Hill, SC
|