Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

changeing name variabels

Status
Not open for further replies.

MarkusLAndersson

Mechanical
Joined
Aug 11, 2005
Messages
20
Location
GB
I would like to get an image to change by cheking a sertain value in an excel sheet.

if the scheet have the value 3 the folowing should happen:

Variable = TextBox273 = ws2.Cells(24, 94).Value ('the value 3)

Image12.Picture = DetailSelect.Image3.Picture

Hovever I want the Image3 to be able to change depending on the value in the sheet.

Could some one help me.

I would really appriciate it
 
I'm not entirely sure what you are trying to accomplish, but hopefully this will point you in the right direction. I renamed the text box on the worksheet to a more descriptive name. I suggest you do the same if you have several objects on a form.

Code:
Sub CheckValue()

Dim wksRefSheet As Worksheet    'Reference to the worksheet
Dim objTextBox  As Object       'Reference to the desired textbox
Dim objMyImage  As Image        'Reference to the desired image
Dim Value       As Integer      'An integer to hold the value to check

Set wksRefSheet = Worksheets("sheet1")
Set objTextBox = wksRefSheet.OLEObjects("txtResult").Object

' OR you could use
'Set objTextBox = wksRefSheet.OLEObjects(1).Object

Set objMyImage = wksRefSheet.OLEObjects("imgMyImage").Object
    
    With wksRefSheet
        Value = Val(.Cells(3, 2))
        objTextBox.Text = Value
        Select Case Value
            Case 1
                objMyImage.Picture = (ChangeImage)
            Case 2
                objMyImage.Picture = (ChangeImage)
            Case 3
                objMyImage.Picture = (ChangeImage)
            Case Else
        End Select
    End With
    
Set objMyImage = Nothing
Set objTextBox = Nothing
Set wksRefSheet = Nothing
End Sub

-JTBorton
Well, You can try banging your head against the wall, but you just end up with lost-time injuries and damaged equipment. [M. Passman]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top