Excel VBA If statement if condition not met Error msgbox and Goto statement to retry

wiesele

New Member
Joined
Jul 14, 2021
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
Hi

Is there a way to write an If statement (if condtion is not meet) to have both a MSGbox and a goto statement?

I would like to add this to the below if statement
'MsgBox "Check Value, Value out of Range Try Again", vbCritical

The below is what I have nowm it works with out the msgbox


Public Sub InputBoxMoveLeft()

Dim strMsg As String
Dim strInputBoxText As String

MsgBox "To Stop Macro Enter a Value of Zero Or Any Negative Value"

RESTART_Macro:
TC:
TC = Application.InputBox("Range is 24.8 - 26.8", "TC 224", "0")
If TC <= 0 Then Exit Sub
If TC < 24.8 Or TC > 26.8 Then GoTo TC

ActiveCell = TC 'Assign the value of the inputbox to a cell.
ActiveCell.Offset(0, 1).Select

strInputBoxText = Application.InputBox("Range is 27 to 29", "Dia 28", "0")
If strInputBoxText <= 0 Then Exit Sub
ActiveCell = strInputBoxText 'Assign the value of the inputbox to a cell.
ActiveCell.Offset(1, -2).Select

GoTo RESTART_Macro:
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Is there a way to write an If statement (if condtion is not meet)
Use a block if with Else
VBA Code:
If something = True Then
    ' condition is met
    ' do this
Else
    'condition is not met
    'do this
End If
 
Upvote 0
Change This:
VBA Code:
If TC < 24.8 Or TC > 26.8 Then GoTo TC
To
VBA Code:
If TC < 24.8 Or TC > 26.8 Then 
MsgBox "You should Enter Value between 24.8  and 26.8"
GoTo TC
End if
 
Upvote 0
You're Welcome & Thanks for follow-up.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,865
Members
449,052
Latest member
Fuddy_Duddy

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