Remove value from drop down list then enters wrong value in worksheet cell

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,859
Office Version
  1. 2007
Platform
  1. Windows
Morning,
On my userform i have a drop down with the following values,
FERRARI STYLE
HYUNDAI UPRATED
ORIGINAL 2B

I wish to remove the FERRARI STYLE thus then leaving the other 2 options.
In the Userform Iniize event i removed this line.

Rich (BB code):
ComboBox2.AddItem "FERRARI STYLE"
But when ive done that the value that is sent to my worksheet is then incorrect.

With FERRARI STYLE left in place i see this completed form of which is correct
Look at REMOTE TYPE & you will see it has HYUNDAI UPRATED shown.
Below is has an automatic option button selected with UPRATED 41835

C.jpg


HERE IS THE ISSUE

W.jpg


With FERRARI STYLE line of code removed i see this completed form of which is incorrect
Look at REMOTE TYPE & you will see it has HYUNDAI UPRATED shown.
Below is has an automatic option button selected with FORD 41835 & also 41835

I am supposed to see the same as above as i had selected HYUNDAI UPRATED
I should only see what is currently shown if ORIGINAL 2B was selected


Below i have supplied the whole code as in the past ive been told to do so.



VBA Code:
 Private Sub TransferButton_Click()
    Dim i As Long, x As Long

    With Sheets("RANGER")

        If TextBox1.Value = "" Then
            MsgBox "NO CUSTOMER'S NAME WAS ENTERED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
            TextBox1.SetFocus
            Exit Sub
        ElseIf TextBox2.Value = "" Then
            MsgBox "YOU DIDNT ENTER THE VIN", vbCritical, "RANGER FIELD EMPTY MESSAGE"
            TextBox2.SetFocus
            Exit Sub
        ElseIf ComboBox1.Value = "" Then
            MsgBox "NO YEAR WAS SELECTED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
            ComboBox1.SetFocus
            Exit Sub
        ElseIf ComboBox2.Value = "" Then
            MsgBox "REMOTE TYPE WAS NOT SELECTED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
            ComboBox2.SetFocus
            Exit Sub
        ElseIf OptionButton5.Value = False And OptionButton6.Value = False And OptionButton5.Visible = True And OptionButton6.Visible = True Then
            MsgBox "NO FINIS NUMBER WAS SELECTED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
            Exit Sub
        ElseIf OptionButton2.Value = False And OptionButton4.Value = False And OptionButton2.Visible = True And OptionButton4.Visible = True Then
            MsgBox "NO UPRATED OPTION WAS SELECTED", vbCritical, "RANGER FIELD EMPTY MESSAGE"
            Exit Sub
        End If
      
        x = 0
        For i = 1 To 4
            If Me.Controls("OptionButton" & i) = True Then
                x = x + 1
                Opt = i
            End If
        Next
        If x = 0 Then
            MsgBox "YOU DIDNT SELECT AN OPTION BUTTON", vbCritical, "RANGER OPTION BUTTON EMPTY MESSAGE"
            Exit Sub
        End If

        .Rows("5:5").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        .Range("B5:I5").Borders.LineStyle = xlContinuous
        .Range("B5:I5").Borders.Weight = xlThin
        .Range("B5:I5").Interior.ColorIndex = 6
        .Range("C5:I5").HorizontalAlignment = xlCenter

        .Range("B5").Value = TextBox1.Text
        .Range("D5").Value = TextBox2.Text
        .Range("F5").Value = TextBox3.Text
        .Range("G5").Value = TextBox4.Text
        .Range("C5").Value = ComboBox1.Text
        .Range("H5").Value = ComboBox2.Text
        .Range("E5").Value = Me.Controls("OptionButton" & Opt).Caption
      
        If ComboBox2.Value = "ORIGINAL 2B" Then
            Unload RangerFormRemote
            RangerPcbNumber.Show
        Else
      
        With .Range("I5")
            .Value = "N/A"
            .Font.Size = 14
            .Font.NAME = "Calibri"
            .Font.Bold = True
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlVAlignCenter
            Unload RangerFormRemote
        End With

        If .AutoFilterMode Then .AutoFilterMode = False
            x = .Cells(.Rows.count, 5).End(xlUp).Row
            .Range("A4:I" & x).Sort Key1:=Range("B5"), Order1:=xlAscending, Header:=xlGuess
            MsgBox "DATABASE UPDATED SUCCESSFULLY", vbInformation, "SUCCESSFUL MESSAGE"
            .Range("B5").Select
        End If

    End With
End Sub
     Private Sub ComboBox2_Change()
        ComboBox2 = UCase(ComboBox2)
        If ComboBox2.ListIndex = 0 Then
        OptionButton5.Visible = True
        OptionButton6.Visible = True
        OptionButton2.Visible = False
        OptionButton4.Visible = False
        OptionButton1.Visible = False
        OptionButton3.Visible = False
        Label8.Visible = True
        Label9.Visible = True
        End If
        If ComboBox2.ListIndex = 1 Then
        OptionButton5.Visible = False
        OptionButton6.Visible = False
        OptionButton2.Visible = True
        OptionButton4.Visible = True
        OptionButton1.Visible = False
        OptionButton3.Visible = False
        Label8.Visible = True
        Label9.Visible = True
        End If
        If ComboBox2.ListIndex = 2 Then
        OptionButton5.Visible = True
        OptionButton6.Visible = True
        OptionButton2.Visible = False
        OptionButton4.Visible = False
        OptionButton1.Visible = False
        OptionButton3.Visible = False
        Label8.Visible = True
        Label9.Visible = True
        End If
        End Sub
    Private Sub OptionButton1_Click()
        If OptionButton1.Value = True Then
        TextBox3.Text = "4488516"
        TextBox4.Text = "REMOTE FOB"
        End If
        End Sub
    Private Sub OptionButton2_Click()
        If OptionButton2.Value = True Then
        TextBox3.Text = "4488516"
        TextBox4.Text = "REMOTE FOB"
        End If
        End Sub
    Private Sub OptionButton3_Click()
        If OptionButton3.Value = True Then
        TextBox3.Text = "1454418"
        TextBox4.Text = "REMOTE FOB"
        End If
        End Sub
    Private Sub OptionButton4_Click()
        If OptionButton4.Value = True Then
        TextBox3.Text = "1454418"
        TextBox4.Text = "REMOTE FOB"
        End If
        End Sub
    Private Sub OptionButton5_Click()
        OptionButton1.Value = True
        End Sub
    Private Sub OptionButton6_Click()
        OptionButton3.Value = True
        End Sub
    Private Sub OptionButton5_Change()
        If OptionButton5.Value = True Then
        OptionButton1.Visible = True
        OptionButton2.Visible = False
        OptionButton3.Visible = False
        OptionButton4.Visible = False
        OptionButton6.Visible = False
        Label8.Visible = False
     Else
        TextBox3.Value = ""
        TextBox4.Value = ""
        End If
        End Sub
    Private Sub OptionButton6_Change()
        If OptionButton6.Value = True Then
        OptionButton1.Visible = False
        OptionButton2.Visible = False
        OptionButton3.Visible = True
        OptionButton4.Visible = False
        OptionButton5.Visible = False
        Label9.Visible = False
    Else
        TextBox3.Value = ""
        TextBox4.Value = ""
        End If
        End Sub
    Private Sub UserForm_Initialize()
        OptionButton1.Visible = False
        OptionButton2.Visible = False
        OptionButton3.Visible = False
        OptionButton4.Visible = False
        OptionButton5.Visible = False
        OptionButton6.Visible = False
        ComboBox1.AddItem "1998"
        ComboBox1.AddItem "1999"
        ComboBox1.AddItem "2000"
        ComboBox1.AddItem "2001"
        ComboBox1.AddItem "2002"
        ComboBox1.AddItem "2003"
        ComboBox1.AddItem "2004"
        ComboBox1.AddItem "2005"
        ComboBox1.AddItem "2006"
        ComboBox1.AddItem "2007"
        ComboBox1.AddItem "2008"
        ComboBox1.AddItem "2009"
        ComboBox1.AddItem "2010"
        ComboBox1.AddItem "2011"
        ComboBox1.AddItem "2012"
        ComboBox2.AddItem "FERRARI STYLE"
        ComboBox2.AddItem "HYUNDAI UPRATED"
        ComboBox2.AddItem "ORIGINAL 2B"
        Label8.Visible = False
        Label9.Visible = False
        TextBox1.SetFocus
        End Sub
    Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
        Dim fndRng As Range
        Dim findString As String
        Dim i As Integer
        Dim wsPostage As Worksheet
        
        findString = Me.TextBox1.Value
        If Len(findString) = 0 Then Exit Sub
        
        Set wsPostage = ThisWorkbook.Worksheets("RANGER")
        i = 1
        Do
            Set fndRng = Nothing
            Set fndRng = wsPostage.Range("B:B").Find(What:=findString & Format(i, " 000"), _
                                                        LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
                                                        SearchDirection:=xlNext, MatchCase:=False)
            If Not fndRng Is Nothing Then
                i = i + 1
                Cancel = True
            End If
        Loop Until fndRng Is Nothing
        
        Me.TextBox1.Value = findString & Format(i, " 000")
        Cancel = False
        
    End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
In Private Sub ComboBox2_Change()
use .Value = what the values will actually be
instead of .ListIndex=
 
Upvote 0
Solution

Forum statistics

Threads
1,225,743
Messages
6,186,778
Members
453,371
Latest member
HMX180

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