VBA questions

Ruger22

New Member
Joined
Mar 31, 2024
Messages
1
Office Version
  1. 2013
Platform
  1. Windows
I have posted a small portion of the code below. I currently have my values hard coded into the program but I would like to have them refer to another sheet to make it easier to update in the future. I'm struggling to find a method that works any help would be greatly appreciated.

If grade = 1 Then
If (TSpsi >= 55000 And TSpsi <= 75000) And TSpsi > 1 Then
ElseIf (TSmpa >= 380 And TSmpa <= 515) And TSmpa > 1 Then
Else
MsgBox ("MTR is not valid! The tensile strength is outside the allowable range. Contact QA Engineer or QA Manager to write NCR.")
Exit Sub
End If
If YSpsi >= 30000 And YSpsi > 1 Then
ElseIf YSmpa >= 205 And YSmpa > 1 Then
Else
MsgBox ("MTR is not valid! The yield strength is below the minimum allowed. Contact QA Engineer or QA Manager to write NCR.")
Exit Sub
End If
If Elong8 >= 23 And Elong8 > 1 Then
ElseIf Elong2 >= 27 And Elong2 > 1 Then
Else
MsgBox ("MTR is not valid! The elongation percentage is below the minimum allowed. Contact QA Engineer or QA Manager to write NCR.")
Exit Sub
End If
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
How about

VBA Code:
With Sheets("Sheet2")
        TSpsi = .Range("A1").Value
        TSmpa = .Range("A2").Value
        YSpsi = .Range("A3").Value
        YSmpa = .Range("A4").Value
        Elong8 = .Range("A5").Value
        Elong2 = .Range("A6").Value
End With
 
Upvote 0
In addition to @Cubist 's suggestion, some of your logic is a bit bloated. For example, where you have:
Rich (BB code):
If YSpsi >= 30000 And YSpsi > 1 Then
if YSpsi is equal to or greater than 30000 - it has to be greater than 1, therefore the second part of your logical test is superfluous. There's numerous examples of that in your code.
 
Upvote 0

Forum statistics

Threads
1,215,274
Messages
6,123,993
Members
449,137
Latest member
abdahsankhan

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