If statment when a image is clicked

Avdyl

New Member
Joined
Mar 7, 2018
Messages
6
Hello guys. Im new to Excel VBA and i need help with a problem im trying to solve.

I have 2 shapes and when i click the shapes the same userform appears. The value that are typed in the userform is gonna be placed in a different cell wich depends on what shape is clicked.

The code i have doesnt work so i would appriciate if somebody could help me out
"
Private Sub CommandButton1_Click()

If HovFelleTilluft = Clicked Then
Sheets("Engine").Range("F24").Value = Txt63T
Else
Sheets("Engine").Range("D24").Value = Txt63T
End If

End Sub
"

I changed the name of the shapes. One shape is called "HovFelleTilluf" and the other "HovFelleAvtrekk"

Sorry for my bad english and thanks for the help =)
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Assuming the "shapes" you refer to are active-x command buttons with captions "HovFelleTilluft" and "HovFelleAvtrekk", and they are on the activesheet. Try:
Code:
Private Sub CommandButton1_Click()
If CommandButton1.Caption = "HovFelleTilluft" Then
    Sheets("Engine").Range("F24").Value = Txt63T
Else
    Sheets("Engine").Range("D24").Value = Txt63T
End If
End Sub
And an analogous script for the other button.
 
Upvote 0
I've got a different take on what you're after.
In a regular module put
Code:
[COLOR=#ff0000]Option Explicit
Public ShpNme As String[/COLOR]
Sub UFshow()
ShpNme = ActiveSheet.Shapes(Application.Caller).name
UserForm1.Show
End Sub
And then in the userform module
Code:
Private Sub CommandButton1_Click()
If ShpNme = "HovFelleTilluft" Then
   Sheets("Engine").Range("F24").Value = Txt63T
Else
   Sheets("Engine").Range("D24").Value = Txt63T
End If
End Sub
The part in red must go at the very top of the module, before any other code
 
Last edited:
Upvote 0
Thank you so much for fast reply guys. I tried your solution JoeMo, but that didnt work. The solution you came up with Fluff worked.

Thank you again for the time =)
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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