Merge 2 VB in one button

Abdulkhadar

Board Regular
Joined
Nov 10, 2013
Messages
119
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.
 

mole999

Moderator
Joined
Oct 23, 2004
Messages
9,940
Office Version
2019, 2016, 2013
Platform
Windows
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:

Abdulkhadar

Board Regular
Joined
Nov 10, 2013
Messages
119
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.
 

Abdulkhadar

Board Regular
Joined
Nov 10, 2013
Messages
119
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
 

Forum statistics

Threads
1,085,181
Messages
5,382,167
Members
401,779
Latest member
Thonor

Some videos you may like

This Week's Hot Topics

Top