ComboBox and Worksheet_Change issues

MassSpecGuru

Board Regular
Joined
Feb 23, 2010
Messages
55
I'm running XL 2003 and I'm having some issues trying to get XL to automatically change the text in a button based on the user's choice from a ComboBox on an XL worksheet.

I'm trying to get the number ouputted by the ComboBox (i.e., the "cell link") to trigger the Worksheet_Change event but it's not behaving as I expect. (Maybe it's my expectations that are wrong?)

I'm new to VBA and am experimenting with some code I found that seems to work for the demonstrated purpose, but I can't seem to be able to tie this together to trigger my code. In fact, when I do it "backwards" and manually enter a number (1 - 6) in the "cell link" referenced in the ComboBox's format control, cell $A$1, everything changes as it should, just not when I choose any items from the ComboBox.

Below is the code for the Worksheet_Change macro as well as my own code. On their own, each works just fine; however, it just seems like the worksheet does not see the changing of the value in the "cell link" as an event change.


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 
'Do nothing if more than one cell is changed or content deleted
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
MsgBox "You just changed " & Target.Address
 
If Target.Address = "$A$1" Then
'Debug.Print "Target = "; Target.Address
 
    'Ensure target is a number before multiplying by 2
    If IsNumeric(Target) Then
 
        'Stop any possible runtime errors and halting code
        On Error Resume Next
 
        'Turn off ALL events so the Target * 2 does not put the code into a loop.
        Application.EnableEvents = False
 
            Target = Target + 0  '* 2
            'Run "RenameButton"
 
 
        'Turn events back on
        Application.EnableEvents = True
 
        Run "RenameButton"
 
        'Allow run time errors again
        On Error GoTo 0
    End If
End If
End Sub

and

Code:
Sub RenameButton()
 
Dim MethodName As String
Dim MethodNumber As Integer
 
MethodNumber = Sheet1.Range("A1").Value
 
Select Case MethodNumber
    Case "1"
        MethodName = "Chloride"
    Case "2"
        MethodName = "Iodide"
    Case "3"
        MethodName = "Nitrate"
    Case "4"
        MethodName = "Nitrite"
    Case "5"
        MethodName = "Phosphate"
    Case "6"
        MethodName = "Sulfate"
End Select
Debug.Print "Method number ="; MethodNumber
Debug.Print "Method name = "; MethodName
 
'don't use "vbCrLf"!  The "Cr" portion generates a square character.
Sheet1.Shapes("Button 2").TextFrame.Characters.Text = _
"Press button to" & vbLf & "generate " & MethodName & " LRN" & vbLf & "upload file"
 
End Sub


Any help, thoughts or ideas would be greatly appreciated.

Thanks!

MSG
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,224,507
Messages
6,179,176
Members
452,893
Latest member
denay

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