Skip to main content

How to organize images automatically in an Excel file using a macro?

If you add multiple images at once to an Excel file, Excel will try to squeeze them in once cell. It will probably look like the screenshot below.

Instead of manually resizing and relocating these images, you can use the macro below to automatically organize all images in milliseconds.

Sub organizeImages()
     lastTop = 0
     staticHeight = 500

     For Each pic In Worksheets("Sheet1").Pictures
          pic.Top = lastTop
          pic.Height = staticHeight
          lastTop = lastTop + pic.Height + 15
          pic.Left = 0
     Next pic
End Sub

Images resized and relocated automatically:

Excel Macro which copies one column to another by matching specific unique column

This is a simple Excel Macro which copy one column to another by comparing specific unique column. There two sheets: Sheet1 and Sheet2. We copy column 2 and 3 at Sheet2 to column 2 and 3 at Sheet1 by matching column 1 at both.

There might be persentage data. You should use NumberFormat parameter in that situation.

Sub CopyCells()
    '*** Defining variables ***'
    Dim Value1, Value2
    Dim RowsCount1, RowsCount2

    '*** Find out rows count ***'
    RowsCount1 = Worksheets("Sheet1").Range("A1").CurrentRegion.Rows.Count
    RowsCount2 = Worksheets("Sheet2").Range("A1").CurrentRegion.Rows.Count

    '*** Copying data ***'
    For C1 = 2 To RowsCount2
Set Value1 = Worksheets("Sheet2").Cells(C1, 1)
For C2 = 3 To RowsCount1
Set Value2 = Worksheets("Sheet1").Cells(C2, 1)
If Value1 = Value2 Then
                Worksheets("Sheet1").Cells(C2, 2) = Worksheets("Sheet2").Cells(C1, 2)
                Worksheets("Sheet1").Cells(C2, 2).NumberFormat = "0.00%"
                Worksheets("Sheet1").Cells(C2, 3) = Worksheets("Sheet2").Cells(C1, 3)
                Worksheets("Sheet1").Cells(C2, 3).NumberFormat = ""
            End If
        Next C2
    Next C1
End Sub

C1 and C2 mean Counter1 and Counter2.