Exceeded Nest In If Function

Luon7951

New Member
Joined
Oct 3, 2017
Messages
4
Hello first time poster. I have exceeded the nest limit for an IF function and I was wondering if someone could help me come up with a solution. I don't mind creating another sheet and then using the VLookup or if there is something better. I am trying to do this in VBA and the only input would be a button press and then entering in the associated number.

PHP:
Dim myvalue As Variant
Dim Qty As Variant
Dim SBP_Ground_Wire_Weight As String    
Dim SBP_Lead_Wire_Weight As String    
Dim SBP_OD_Preform_Weight As String    
Dim SBP_ID_Preform_Weight As String
Dim SBP_9CH_Ground_Wire_Weight As String    
Dim SBP_9CH_Lead_Wire_Weight As String    
Dim SBP_9CH_OD_Preform_Weight As String   
Dim SBP_9CH_ID_Preform_Weight As String     
Dim DD_4CH_Lead_Wire_Weight As String    
Dim DD_4CH_OD_Preform_Weight As String    
Dim DD_4CH_ID_Preform_Weight As String          
Dim DD_6CH_Ground_Wire_Weight As String    
Dim DD_6CH_Lead_Wire_Weight As String    
Dim DD_6CH_OD_Preform_Weight As String    
Dim DD_6CH_ID_Preform_Weight As String

'Prompt for Material Number
myvalue = InputBox("Material Number?")
If myvalue = 100154016 Then    GoTo SBP_Ground_Wire
    ElseIf myvalue = 1001 Then    GoTo SBP_Lead_Wire
    ElseIf myvalue = 1002 Or 10002 Then    GoTo SBP_OD_Preform
    ElseIf myvalue = 1003 Or 10003 Then    GoTo SBP_ID_Preform

If myvalue = 8284 Then    GoTo SBP_9CH_Ground_Wire
    ElseIf myvalue = 8285 Then    GoTo SBP_9CH_Lead_Wire
    ElseIf myvalue = 7905 Or 7902 Then    GoTo SBP_9CH_OD_Preform
    ElseIf myvalue = 4019 Or 4012 Then    GoTo SBP_9CH_ID_Preform        

If myvalue = 6305 Then    GoTo DD_4CH_Lead_Wire
    ElseIf myvalue = 6325 Or 6306 Then    GoTo DD_4CH_OD_Preform
    ElseIf myvalue = 2103 Or 2104 Then    GoTo DD_4CH_ID_Preform        

If myvalue = 2109 Then    GoTo DD_6CH_Ground_Wire
    ElseIf myvalue = 2108 Then    GoTo DD_6CH_Lead_Wire
    ElseIf myvalue = 2105 Or 2106 Then    GoTo 
DD_6CH_OD_Preform
    ElseIf myvalue = 2104 Or 2103 Then    GoTo DD_6CH_ID_Preform

Else    MsgBox "Material Number not Recognized"    ActiveSheet.Protect Password:="-----"    
Exit Sub    
End If
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
You haven't exceed the number of nested ifs

In fact you haven't nested them at all.

For each and every if you must have an "End If". You have zero (your only one is outside the Sub so doesn't count.

You might want to look at the "Select Case" logic instead as well
 
Upvote 0
You haven't exceed the number of nested ifs

In fact you haven't nested them at all.

For each and every if you must have an "End If". You have zero (your only one is outside the Sub so doesn't count.

You might want to look at the "Select Case" logic instead as well

Thank you so much for the response. That was a pretty dumb mistake, but I was able to correct it thanks to your direction. I appreciate it!
 
Upvote 0

Forum statistics

Threads
1,215,088
Messages
6,123,057
Members
449,091
Latest member
ikke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top