Merge 2 VB in one button

Abdulkhadar

Board Regular
Joined
Nov 10, 2013
Messages
165
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Dear Excel Experts,
I want to operate both the VBs in button2.

Sub Prog_Button2_Click()
Dim i As Picture
Dim j As String
On Error Resume Next
If Target.Address = Range("c3").Address Then
ActiveSheet.Pictures.Delete
j = "C:\Users\CSSHS CKD\Dropbox\Photo\" & Range("c3") & Value & ".jpg"
With Range("k25")
Set i = ActiveSheet.Pictures.Insert(j)
i.Height = 100
i.Weight = 95
i.Top = .Top
i.Left = .Left
i.Placement = xlMoveAndSize
End With
End If
Sheets("Prog").PrintOut
End Sub

Sub Prog_Button3_Click()
Dim i As Picture
Dim j As String
On Error Resume Next
If Target.Address = Range("d4").Address Then
ActiveSheet.Pictures.Delete
j = "C:\Users\CSSHS CKD\Dropbox\Photo\" & Range("d4") & Value & ".jpg"
With Range("g8")
Set i = ActiveSheet.Pictures.Insert(j)
i.Height = 75
i.Weight = 70
i.Top = .Top
i.Left = .Left
i.Placement = xlMoveAndSize
End With
End If
End Sub

Thanks in advance.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
you could do
VBA Code:
sub runme()
Prog_Button2_Click
Prog_Button3_Click
end sub

OR

Code:
Sub Prog_Button2_Click()
Dim i As Picture
Dim j As String
On Error Resume Next
If Target.Address = Range("c3").Address Then
ActiveSheet.Pictures.Delete
j = "C:\Users\CSSHS CKD\Dropbox\Photo\" & Range("c3") & Value & ".jpg"
With Range("k25")
Set i = ActiveSheet.Pictures.Insert(j)
i.Height = 100
i.Weight = 95
i.Top = .Top
i.Left = .Left
i.Placement = xlMoveAndSize
End With
End If
Sheets("Prog").PrintOut
Prog_Button3_Click
End Sub

Sub Prog_Button3_Click()
Dim i As Picture
Dim j As String
On Error Resume Next
If Target.Address = Range("d4").Address Then
ActiveSheet.Pictures.Delete
j = "C:\Users\CSSHS CKD\Dropbox\Photo\" & Range("d4") & Value & ".jpg"
With Range("g8")
Set i = ActiveSheet.Pictures.Insert(j)
i.Height = 75
i.Weight = 70
i.Top = .Top
i.Left = .Left
i.Placement = xlMoveAndSize
End With
End If
End Sub

add Prog_Button3_Click into the Prog_Button2_Click code
 
Last edited:
Upvote 0
Thanks for your quick reply sir,
I tried both code but only one image displays.

you could do
VBA Code:
sub runme()
Prog_Button2_Click
Prog_Button3_Click
end sub

OR

Code:
Sub Prog_Button2_Click()



End With
End If
Sheets("Prog").PrintOut
Prog_Button3_Click
End Sub

[B]add Prog_Button3_Click into the Prog_Button2_Click code[/B]
[/QUOTE]
Thanks for your quick reply sir,
I tried both code but only one image displays.
 
Upvote 0
Sorry to disturb you,
In VB

ActiveSheet.Pictures.Delete

this function deletes all the pictures in the active sheet. i want to delete only cell "K25" contain picture to add another picture in that place.

you could do


add Prog_Button3_Click into the Prog_Button2_Click code
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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