Detect image and fit row if not

PIsabel

Board Regular
Joined
Feb 4, 2014
Messages
121
Office Version
  1. 365
Platform
  1. Windows
Hello.
I'm working on a table of articles with images.
Each line has a fixed height of 100.
I need a code that identifies the lines that do not have an image and that reduces these same lines to a height of 15

Can some help me?

Thanks
_10003.jpg
_10004.jpg
 
Done!!!
It works impeccably well.
Thanks to everyone, especially "jolivanes"





Works on your example.
Code:
Sub Maybe()
Dim sh1 As Worksheet, shp As Shape, rng As Range, c As Range
Dim lr As Long, j As Long, rw
Set sh1 = Worksheets("Sheet1")
lr = sh1.Cells(Rows.Count, 2).End(xlUp).Row
Set rng = sh1.Range(sh1.Cells(3, 1), sh1.Cells(lr, 1))
Application.ScreenUpdating = False
    With sh1
    For Each c In rng
        For Each shp In .Shapes
            If Not Intersect(shp.TopLeftCell, .Range(c.Address)) Is Nothing Then
                shp.Placement = xlMoveAndSize
                    rw = rw & "|" & c.Row
                Exit For
            End If
        Next shp
    Next c
    End With
    rw = Split(Mid(rw, 2), "|")
    For j = LBound(rw) To UBound(rw)
        sh1.Rows(rw(j)).EntireRow.Hidden = True
    Next j
    With rng
        .SpecialCells(xlCellTypeVisible).RowHeight = 15
        .EntireRow.Hidden = False
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
This might be more pleasing to the eye.
Code:
Sub Maybe_3()
Dim sh1 As Worksheet, rng As Range, lr As Long, c As Range, rws As Range
Set sh1 = Worksheets("Sheet1")
lr = sh1.Cells(Rows.Count, 2).End(xlUp).Row
Set rng = sh1.Range(sh1.Cells(3, 1), sh1.Cells(lr, 1))
Application.ScreenUpdating = False
For Each c In rng
    If fcnHasImage(c) = False Then
        If Not rws Is Nothing Then
            Set rws = Union(rws, c.EntireRow)
                Else
            Set rws = c.EntireRow
        End If
    End If
Next c
If Not rws Is Nothing Then rws.RowHeight = 15
Set rws = Nothing
Application.ScreenUpdating = True
End Sub

Code:
Public Function fcnHasImage(ByVal Target As Range) As Boolean
    Dim bResult As Boolean, shp As Shape
    bResult = False
    If Not ActiveSheet.Shapes Is Nothing Then
        For Each shp In ActiveSheet.Shapes
            If shp.TopLeftCell.Address = Target.Address Then
                shp.Placement = xlMoveAndSize
                bResult = True
            End If
        Next shp
    End If
    fcnHasImage = bResult
End Function
 
Upvote 0

Forum statistics

Threads
1,215,221
Messages
6,123,701
Members
449,117
Latest member
Aaagu

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