Mixphonics
New Member
- Joined
- Sep 21, 2012
- Messages
- 21
Hello, I am hoping someone can help me with the code I have below. I am trying to figure out what is wrong with my syntax.
The particular part of the code I am having problems with is this part:
If Corktype = "agglomerated" Then
ElseIf InitQty < 2 Then ReqTests = 0
ElseIf InitQty <= 15 And InitQty >= 2 Then ReqTests = 2
ElseIf InitQty <= 25 And InitQty > 15 Then ReqTests = 3
ElseIf InitQty <= 90 And InitQty > 25 Then ReqTests = 5
ElseIf InitQty <= 150 And InitQty > 90 Then ReqTests = 5
ElseIf InitQty <= 280 And InitQty > 150 Then ReqTests = 8
ElseIf InitQty > 281 Then ReqTests = 13
Else
End If
If Corktype = "natural" Then
ElseIf InitQty < 2 Then ReqTests = 0
ElseIf InitQty <= 8 And InitQty >= 2 Then ReqTests = 2
ElseIf InitQty <= 15 And InitQty > 8 Then ReqTests = 3
ElseIf InitQty <= 25 And InitQty > 15 Then ReqTests = 5
ElseIf InitQty <= 50 And InitQty > 25 Then ReqTests = 8
ElseIf InitQty <= 90 And InitQty > 50 Then ReqTests = 13
ElseIf InitQty <= 150 And InitQty > 90 Then ReqTests = 20
Else
End If
I've tried messing around with it in different ways including UCase("agglomerated") etc... and doing a instr(corktype, "natural") but the vba code seems to step right through the fact that if the variable Corktype = "natural" and the code says If Corktype = "agglomerated" then it continues through the code even though the variable Corktype does not equal "agglomerated".
Any suggestions?
I have included the entire Macro below for anyone's review.
Best regards,
Mixphonics
Sub Macro()
'Global Variables
Dim QtyTests As Integer, ReqTests As Integer, InitQty As Integer, Cork As String, Corktype As String
Dim result As Integer
'select starting position of macro
Sheets("ETS Testing").Select
Range("G4").Select
'Bale Qty for each grade
InitQty = ActiveCell.Offset(0, 5).Value
'Corkgrade & type for each lot/grade
Cork = ActiveCell.Offset(0, 1).Value
'define the range of the 20 possible bales tested at ETS's results
Range(ActiveCell.Offset(0, 8), ActiveCell.Offset(0, 27)).Select
QtyTests = WorksheetFunction.CountA(Range(ActiveCell.Offset(0, 8), ActiveCell.Offset(0, 27)))
ActiveCell.Offset(0, -8).Select
result = InStr(Cork, "C3")
If result = 0 Then Corktype = "natural" Else Corktype = "agglomerated"
'This is the start of the problem code, even though Corktype is "natural is still proceeds through if statement
If Corktype = "agglomerated" Then
ElseIf InitQty < 2 Then ReqTests = 0
ElseIf InitQty <= 15 And InitQty >= 2 Then ReqTests = 2
ElseIf InitQty <= 25 And InitQty > 15 Then ReqTests = 3
ElseIf InitQty <= 90 And InitQty > 25 Then ReqTests = 5
ElseIf InitQty <= 150 And InitQty > 90 Then ReqTests = 5
ElseIf InitQty <= 280 And InitQty > 150 Then ReqTests = 8
ElseIf InitQty > 281 Then ReqTests = 13
Else
End If
If Corktype = "natural" Then
ElseIf InitQty < 2 Then ReqTests = 0
ElseIf InitQty <= 8 And InitQty >= 2 Then ReqTests = 2
ElseIf InitQty <= 15 And InitQty > 8 Then ReqTests = 3
ElseIf InitQty <= 25 And InitQty > 15 Then ReqTests = 5
ElseIf InitQty <= 50 And InitQty > 25 Then ReqTests = 8
ElseIf InitQty <= 90 And InitQty > 50 Then ReqTests = 13
ElseIf InitQty <= 150 And InitQty > 90 Then ReqTests = 20
Else
End If
End Sub
The particular part of the code I am having problems with is this part:
If Corktype = "agglomerated" Then
ElseIf InitQty < 2 Then ReqTests = 0
ElseIf InitQty <= 15 And InitQty >= 2 Then ReqTests = 2
ElseIf InitQty <= 25 And InitQty > 15 Then ReqTests = 3
ElseIf InitQty <= 90 And InitQty > 25 Then ReqTests = 5
ElseIf InitQty <= 150 And InitQty > 90 Then ReqTests = 5
ElseIf InitQty <= 280 And InitQty > 150 Then ReqTests = 8
ElseIf InitQty > 281 Then ReqTests = 13
Else
End If
If Corktype = "natural" Then
ElseIf InitQty < 2 Then ReqTests = 0
ElseIf InitQty <= 8 And InitQty >= 2 Then ReqTests = 2
ElseIf InitQty <= 15 And InitQty > 8 Then ReqTests = 3
ElseIf InitQty <= 25 And InitQty > 15 Then ReqTests = 5
ElseIf InitQty <= 50 And InitQty > 25 Then ReqTests = 8
ElseIf InitQty <= 90 And InitQty > 50 Then ReqTests = 13
ElseIf InitQty <= 150 And InitQty > 90 Then ReqTests = 20
Else
End If
I've tried messing around with it in different ways including UCase("agglomerated") etc... and doing a instr(corktype, "natural") but the vba code seems to step right through the fact that if the variable Corktype = "natural" and the code says If Corktype = "agglomerated" then it continues through the code even though the variable Corktype does not equal "agglomerated".
Any suggestions?
I have included the entire Macro below for anyone's review.
Best regards,
Mixphonics
Sub Macro()
'Global Variables
Dim QtyTests As Integer, ReqTests As Integer, InitQty As Integer, Cork As String, Corktype As String
Dim result As Integer
'select starting position of macro
Sheets("ETS Testing").Select
Range("G4").Select
'Bale Qty for each grade
InitQty = ActiveCell.Offset(0, 5).Value
'Corkgrade & type for each lot/grade
Cork = ActiveCell.Offset(0, 1).Value
'define the range of the 20 possible bales tested at ETS's results
Range(ActiveCell.Offset(0, 8), ActiveCell.Offset(0, 27)).Select
QtyTests = WorksheetFunction.CountA(Range(ActiveCell.Offset(0, 8), ActiveCell.Offset(0, 27)))
ActiveCell.Offset(0, -8).Select
result = InStr(Cork, "C3")
If result = 0 Then Corktype = "natural" Else Corktype = "agglomerated"
'This is the start of the problem code, even though Corktype is "natural is still proceeds through if statement
If Corktype = "agglomerated" Then
ElseIf InitQty < 2 Then ReqTests = 0
ElseIf InitQty <= 15 And InitQty >= 2 Then ReqTests = 2
ElseIf InitQty <= 25 And InitQty > 15 Then ReqTests = 3
ElseIf InitQty <= 90 And InitQty > 25 Then ReqTests = 5
ElseIf InitQty <= 150 And InitQty > 90 Then ReqTests = 5
ElseIf InitQty <= 280 And InitQty > 150 Then ReqTests = 8
ElseIf InitQty > 281 Then ReqTests = 13
Else
End If
If Corktype = "natural" Then
ElseIf InitQty < 2 Then ReqTests = 0
ElseIf InitQty <= 8 And InitQty >= 2 Then ReqTests = 2
ElseIf InitQty <= 15 And InitQty > 8 Then ReqTests = 3
ElseIf InitQty <= 25 And InitQty > 15 Then ReqTests = 5
ElseIf InitQty <= 50 And InitQty > 25 Then ReqTests = 8
ElseIf InitQty <= 90 And InitQty > 50 Then ReqTests = 13
ElseIf InitQty <= 150 And InitQty > 90 Then ReqTests = 20
Else
End If
End Sub