Search all sheets in workbook for cell value and insert image

Pikachu90

New Member
Joined
Jan 3, 2016
Messages
2
I'm having trouble with my macro and I feel like I'm not seeing things clearly anymore, any help is helpful, especially with the idea of looping

1. Prompt user for folder
(I have this done and I stored it as MyDir as a string)

2. Folder contains image files with names that are found in a cell in a particular sheet
(So imageABC.emf has a sheet Apples which contains a cell that =imageABC.emf)

3. After picking up the file name imageABC.emf, the macro looks through the active workbook for the cell containing that value, and inserts the file "in" the cell.

4. Then it loops back and repeats the process for the rest of the folder contents. If the file name is not found in the workbook, it's skipped (or msgbox alert) and continues with the rest


Thanks in advance. I will post what I have as soon as I charge my laptop
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Sub Macro5()

Dim MyDir As String

With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
If .Show <> -1 Then MsgBox "No Folder Selected! Exit Sub.": Exit Sub
MyDir = .SelectedItems(1)

End With

'------------------------------------------------------------------------------

Dim FilePath As String
Dim FileName As String
Dim File As String

Dim WrkSheet As Worksheet
Dim FoundName As Variant
Dim CellAddress As Variant



FilePath = MyDir & "\"
FileName = Dir(FilePath, vbNormal)

For Each WrkSheet In ActiveWorkbook.Worksheets

With WrkSheet
Set FoundName = .UsedRange.Find(what:=FileName)
If Not FoundName Is Nothing Then 'check to see if CellAddress is something Then
File = FilePath + FoundName

MsgBox FoundName & " FoundName"


CellAddress = FoundName.Address

activesheet.Pictures.Insert (File)

Else

MsgBox "Helloooo There"

End If
'FileName = Dir
End With
Next WrkSheet




End Sub

'CURRENTLY SEEMS TO BE ABLE TO LOOK THROUGH ALL SHEETS FOR THE FIRST FILE NAME IT GETS FROM THE FOLDER AND PASTES EQUAL NUMBER
'OF IMAGES INTO ACTIVE CELL AND NOT CELL THAT THE "FIND" FINDS but ONLY WHEN THE FIRST FILE SEARCHED FOR EXISTS IN THE ACTIVE SHEET?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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