How to display different message box

kimberly090

Board Regular
Joined
May 22, 2014
Messages
99
Hi,

I wish to display a different message box when it meet the following requirement:

1. When textbox8 value less than 3, message box will show textbox8 is out of range, do user want to continue store the data, if user hit yes, then will continue store the data but if user select no, will ask user to re-enter textbox8 value then only store data.

2. When textbox8 value is between 3 to 3.2, message box will show textbox8 is between 3 to 3.2, please be aware, and show a OK button for user to click and store the data.

I have try to add another message box inside but it will only check the first condition.


Code:
Sheets("Overall").Activate    
    With Me
        If Len(.ComboBox5.Value) * Len(.TextBox4.Value) * Len(.TextBox5.Value) * Len(.TextBox6.Value) * Len(.ComboBox6.Value) * Len(.TextBox7.Value) * Len(.TextBox8.Value) = 0 Then
            MsgBox "Please Complete All Fields Before Submit"
        Else
            
            If CSng(.TextBox8.Text) < 3 Then
                If MsgBox("TextBox8 less than 3.0" & vbLf & vbLf & _
                          "Do you wish to continue?", vbYesNo, "Exceeds") = vbNo Then
                          
                    MsgBox "user to re-type the value in TextBox8.", vbInformation, "Title"
                    
                    TextBox8.SetFocus
                      
                              Else
            
            If CSng(.TextBox8.Text) >= 3 And CSng(.TextBox8.Text) <= 3.2 Then
            
            MsgBox "TextBox8 between 3 to 3.2, Aware!!!", , "Alert"
                
                      
                      Exit Sub
                      
                                                 End If
             End If
                                           End If
             End If
            eRow = Sheet4.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
                   Cells(eRow, 11).Value = ComboBox5.Text
                   Cells(eRow, 7).Value = TextBox4.Text
                   Cells(eRow, 8).Value = TextBox5.Text
                   Cells(eRow, 14).Value = TextBox6.Text
                   Cells(eRow, 16).Value = ComboBox6.Text
                   Cells(eRow, 12).Value = TextBox7.Text
                   Cells(eRow, 13).Value = TextBox8.Text
                   Cells(eRow, 19).Value = TextBox9.Text
            
        End If
    End With
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try this...

Code:
    Sheets("Overall").Activate
    [color=darkblue]With[/color] Me
        [color=darkblue]If[/color] Len(.ComboBox5.Value) * Len(.TextBox4.Value) * Len(.TextBox5.Value) * Len(.TextBox6.Value) * Len(.ComboBox6.Value) * Len(.TextBox7.Value) * Len(.TextBox8.Value) = 0 [color=darkblue]Then[/color]
            MsgBox "Please Complete All Fields Before Submit"
        [color=darkblue]Else[/color]
            
            [color=darkblue]If[/color] [color=darkblue]CSng[/color](.TextBox8.Text) < 3 [color=darkblue]Then[/color]
                [color=darkblue]If[/color] MsgBox("TextBox8 less than 3.0" & vbLf & vbLf & _
                          "Do you wish to continue?", vbYesNo, "Exceeds") = vbNo [color=darkblue]Then[/color]
                    
                    MsgBox "user to re-type the value in TextBox8.", vbInformation, "Title"
                    TextBox8.SetFocus
                    [color=darkblue]Exit[/color] [color=darkblue]Sub[/color]
                [color=darkblue]End[/color] [color=darkblue]If[/color]
                
            [color=darkblue]ElseIf[/color] [color=darkblue]CSng[/color](.TextBox8.Text) <= 3.2 [color=darkblue]Then[/color]
                
                MsgBox "TextBox8 between 3 to 3.2, Aware!!!", , "Alert"
                
            [color=darkblue]End[/color] [color=darkblue]If[/color]
            
            eRow = Sheet4.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
            Cells(eRow, 11).Value = ComboBox5.Text
            Cells(eRow, 7).Value = TextBox4.Text
            Cells(eRow, 8).Value = TextBox5.Text
            Cells(eRow, 14).Value = TextBox6.Text
            Cells(eRow, 16).Value = ComboBox6.Text
            Cells(eRow, 12).Value = TextBox7.Text
            Cells(eRow, 13).Value = TextBox8.Text
            Cells(eRow, 19).Value = TextBox9.Text
            
        [color=darkblue]End[/color] [color=darkblue]If[/color]
    [color=darkblue]End[/color] [color=darkblue]With[/color]
 
Upvote 0
Try this...

Code:
    Sheets("Overall").Activate
    [COLOR=darkblue]With[/COLOR] Me
        [COLOR=darkblue]If[/COLOR] Len(.ComboBox5.Value) * Len(.TextBox4.Value) * Len(.TextBox5.Value) * Len(.TextBox6.Value) * Len(.ComboBox6.Value) * Len(.TextBox7.Value) * Len(.TextBox8.Value) = 0 [COLOR=darkblue]Then[/COLOR]
            MsgBox "Please Complete All Fields Before Submit"
        [COLOR=darkblue]Else[/COLOR]
            
            [COLOR=darkblue]If[/COLOR] [COLOR=darkblue]CSng[/COLOR](.TextBox8.Text) < 3 [COLOR=darkblue]Then[/COLOR]
                [COLOR=darkblue]If[/COLOR] MsgBox("TextBox8 less than 3.0" & vbLf & vbLf & _
                          "Do you wish to continue?", vbYesNo, "Exceeds") = vbNo [COLOR=darkblue]Then[/COLOR]
                    
                    MsgBox "user to re-type the value in TextBox8.", vbInformation, "Title"
                    TextBox8.SetFocus
                    [COLOR=darkblue]Exit[/COLOR] [COLOR=darkblue]Sub[/COLOR]
                [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
                
            [COLOR=darkblue]ElseIf[/COLOR] [COLOR=darkblue]CSng[/COLOR](.TextBox8.Text) <= 3.2 [COLOR=darkblue]Then[/COLOR]
                
                MsgBox "TextBox8 between 3 to 3.2, Aware!!!", , "Alert"
                
            [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
            
            eRow = Sheet4.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
            Cells(eRow, 11).Value = ComboBox5.Text
            Cells(eRow, 7).Value = TextBox4.Text
            Cells(eRow, 8).Value = TextBox5.Text
            Cells(eRow, 14).Value = TextBox6.Text
            Cells(eRow, 16).Value = ComboBox6.Text
            Cells(eRow, 12).Value = TextBox7.Text
            Cells(eRow, 13).Value = TextBox8.Text
            Cells(eRow, 19).Value = TextBox9.Text
            
        [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]

You saved my life~
that exactly what I want~
thank you so so so much
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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