A wonderful forum member (Perpa) helped me modify some code he posted to insert images in rows of 3 in a spreadsheet. He suggested I start a new thread for further modifications.
The macro works very well to insert images in a fresh sheet; however, I need to designate the starting point. For example, if I have data in the sheet from A1:N200, I need the images to start at B:205. Running this macro always inserts the images beginning in row 1. Can anyone help with a modification to start at the active cell or designate a starting cell?
Thanks so much!!
Robyn
https://www.mrexcel.com/forum/excel...olumns-unlimited-rows-empty-cell-between.html
The macro works very well to insert images in a fresh sheet; however, I need to designate the starting point. For example, if I have data in the sheet from A1:N200, I need the images to start at B:205. Running this macro always inserts the images beginning in row 1. Can anyone help with a modification to start at the active cell or designate a starting cell?
Thanks so much!!
Robyn
https://www.mrexcel.com/forum/excel...olumns-unlimited-rows-empty-cell-between.html
Rich (BB code):
Sub AddOlEObject_2x3Rev()
Dim mainWorkBook As Workbook
Dim counter, rw, LR, ac As Long
Dim RowsOfPics As Long
Application.ScreenUpdating = False
Set mainWorkBook = ActiveWorkbook
Sheets("Sheet2").Select
Columns("A:A").Select
Selection.ClearContents
Range("I2:I100").Select
Selection.ClearContents
Sheets("Write-up").Activate 'Change the sheet name from "Write-up" to the sheet name where you want your pictures to go
'Change the folderpath to wherever your pictures are coming from
Folderpath = InputBox("Enter the complete folder path to your files" & Chr(13) & " in this format: 'C:\yourPath\folder1'")
Set fso = CreateObject("Scripting.FileSystemObject")
NoOfFiles = fso.GetFolder(Folderpath).Files.Count
Set listfiles = fso.GetFolder(Folderpath).Files
RowsOfPics = NoOfFiles / 3
If RowsOfPics - Int(RowsOfPics) <> 0 Then
RowsOfPics = (RowsOfPics + 1) * 4
Else
RowsOfPics = (RowsOfPics) * 4
End If
Rows("1:" & RowsOfPics).Insert shift:=xlDown
rw = 1
For Each fls In listfiles
Sheets("Sheet2").Range("A" & rw).Value = fls
rw = rw + 1
Next fls
Call SortMyFiles
LR = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row
'ac = ActiveCell.Row
For rw = 1 To LR Step 3
Sheets("Write-up").Range("B" & rw + 1).Value = Sheets("Sheet2").Range("I" & rw).Value
Sheets("Write-up").Range("B" & rw + 1).RowHeight = 16
'Sheets("Write-up").Range("B" & rw).ColumnWidth = 50 'Adjust COLUMNS to fit your pictures
Sheets("Write-up").Range("B" & rw).RowHeight = 220 'Adjust ROWS to fit your pictures
Call insert1(Sheets("Sheet2").Range("A" & rw).Value, rw)
Next rw
For rw = 1 To LR Step 3
Sheets("Write-up").Range("E" & rw + 1).Value = Sheets("Sheet2").Range("I" & rw + 1).Value
'Sheets("Write-up").Range("E" & rw).ColumnWidth = 50 'Adjust COLUMNS to fit your pictures
Call insert2(Sheets("Sheet2").Range("A" & rw + 1).Value, rw)
Next rw
For rw = 1 To LR Step 3
Sheets("Write-up").Range("M" & rw + 1).Value = Sheets("Sheet2").Range("I" & rw + 2).Value
'Sheets("Write-up").Range("M" & rw).ColumnWidth = 50 'Adjust COLUMNS to fit your pictures
Call insert3(Sheets("Sheet2").Range("A" & rw + 2).Value, rw)
Next rw
Sheets("Write-up").Activate
Application.ScreenUpdating = True
Sheets("Master").Select
Range("A1").Select
End Sub
Sub SortMyFiles()
Dim LR, rw As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
Sheets("Sheet2").Select
Range("A1:A" & LR).Select
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=Range("A1"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet2").Sort
.SetRange Range("A1:A" & LR)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
With Sheets("Sheet2")
.Activate
LR = .Range("A" & Rows.Count).End(xlUp).Row
For rw = 2 To LR
'Copies formula
.Range("I1").Copy 'This is the formula to find the filename
.Range("I" & rw).PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Next rw
End With
Range("A" & LR + 1).Activate
Sheets("Write-up").Activate
End Sub
Function insert1(PicPath, counter1)
'Formats Column A Pictures
With ActiveSheet.Pictures.Insert(PicPath)
With .ShapeRange
.LockAspectRatio = msoTrue 'If you uncomment both Width and Height lines below change to 'msoFalse'
'.Width = 50 'Adjust to change the WIDTH of your pictures - COMMENTED OUT
.Height = 215 'Adjust to change the HEIGHT of your pictures
End With
.Left = ActiveSheet.Range("B" & counter1).Left
.Top = ActiveSheet.Range("B" & counter1).Top
.Placement = 1
.PrintObject = True
End With
ActiveCell.Offset(1, 0).Select
End Function
Function insert2(PicPath, counter2)
'Formats Column B Pictures
With ActiveSheet.Pictures.Insert(PicPath)
With .ShapeRange
.LockAspectRatio = msoTrue 'If you uncomment both Width and Height lines below change to 'msoFalse'
'.Width = 50 'Adjust to change the WIDTH of your pictures - COMMENTED OUT with the single quote
.Height = 215 'Adjust to change the HEIGHT of your pictures
End With
.Left = ActiveSheet.Range("E" & counter2).Left
.Top = ActiveSheet.Range("E" & counter2).Top
.Placement = 1
.PrintObject = True
End With
End Function
Function insert3(PicPath, counter3)
'Formats Column C Pictures
With ActiveSheet.Pictures.Insert(PicPath)
With .ShapeRange
.LockAspectRatio = msoTrue 'If you uncomment both Width and Height lines below change to 'msoFalse'
'.Width = 50 'Adjust to change the WIDTH of your pictures - COMMENTED OUT with the single quote
.Height = 215 'Adjust to change the HEIGHT of your pictures
End With
.Left = ActiveSheet.Range("M" & counter3).Left
.Top = ActiveSheet.Range("M" & counter3).Top
.Placement = 1
.PrintObject = True
End With
End Function