musicfreer
New Member
- Joined
- Aug 26, 2022
- Messages
- 4
Hi,
I have a VBA which works fine in original worksheet with a button. However, when I copied the worksheet, the button is still referencing to the original worksheet. I am totally new to coding. Please teach me how to correct the VBA or button.
Thank you
I have a VBA which works fine in original worksheet with a button. However, when I copied the worksheet, the button is still referencing to the original worksheet. I am totally new to coding. Please teach me how to correct the VBA or button.
Thank you
VBA Code:
Sub InsertPicsr1()
Dim fPath As String, fName As String
Dim r As Range
Application.ScreenUpdating = False
fPath = "E:\listings\listing photo\"
For Each r In Range("D2:D" & Cells(Rows.Count, 4).End(xlUp).Row)
On Error GoTo errHandler
If r.Value <> "" Then
With ActiveSheet
.Shapes.AddPicture fPath & r.Value & ".jpg", _
msoFalse, msoTrue, _
.Cells(r.Row, 2).Left, _
.Cells(r.Row, 2).Top, _
.Columns(2).Width, _
.Rows(r.Row).Height
End With
End If
errHandler:
If Err.Number <> 0 Then
Debug.Print Err.Number & ", " & Err.Description & ", " & r.Value
On Error GoTo -1
End If
Next r
Application.ScreenUpdating = True
End Sub