JuniperTree wrote:
I'm trying to do the following:
iGroupNum = variable
IF (the right 2 digits of iGroupNum) = "01" or "02" then
If (the right 2 of iGroupNum) = "01" then
iGroupNum = whatever is left minus the 2 right digits (i.e.
3001 would be igroupnum= 30) * 2
Else If (the right 2 digits of iGroupNum) = "02" then
iGroupNumb= whatever is left minus the 2 right digits * 2 + 1
End If
Else (the right 2 digits of iGroupNum < "01" or "02" then
iGroupNum = iGroupNum* 2
End If
Essentially, I'm trying to move cells from one page with a designated
group number to another page. They will go into every other row except
for when the right 2 digits of the designated group number is "01" or
"02". In this case they will end up in consecutive rows.
So far I have:
If Right(iGroupNum, 2) = "01" Or "02" Then
If Right(iGroupNum, 2) = "01" Then
iGroupNum = Left(iGroupNum, Len(iGroupNum) - 2) * 2
Else
iGroupNum = iGroupNum * 2 + 1
End If
End If
If Right(iGroupNum, 2) < "01" Or "02" Then
iGroupNum = iGroupNum
End If
Unfortunately the code is going into the first IF statement even if
iGroupNum = 2 (should only go in if it were 201 or 202)
End If
Help?
Newbie VB gal.
I am not really sure of the significance of the code
If Right(iGroupNum, 2) < "01" Or "02" Then
iGroupNum = iGroupNum
End If
Here is your code with a slight change (you can't just use OR between
two conditions for an IF statement, you need to have If x=y or if x=z
then
Right now, the code checks to see if the right two characters are "01",
or "02". If they are, then it takes the left two characters and
multiplies them by 2.
If the right two characters are not "01" or "02" then igroupnum =
igroupnum*2+1
Is that what you were trying to do? Why is the other IF statement
making igroupnum=igroupnum?
If Right(igroupnum, 2) = "01" Or Right(igroupnum, 2) = "02" Then
If Right(igroupnum, 2) = "01" Then
igroupnum = Left(igroupnum, Len(igroupnum) - 2) * 2
Else
igroupnum = igroupnum * 2 + 1
End If
End If
I am thinking that you want the code to do something like the
following:
If Right(igroupnum, 2) = "01" Or Right(igroupnum, 2) = "02" Then
If Right(igroupnum, 2) = "01" Then
igroupnum = Left(igroupnum, Len(igroupnum) - 2) * 2
ElseIf Right(igroupnum, 2) = "02" Then
igroupnum = igroupnum * 2 + 1
Else
igroupnum = igroupnum
End If
End If
Please let me know if that helps.