0

I need to select all rows smaller than 16 points in order to manually delete them. Programatically deleting them rescales images on the spreadsheet and breaks it (ChemBio generated chemical structures).

My code works up until it makes the selection:

Sub FindAndRemoveSmallRows()
Dim a As Range, b As Range, c As String
Set a = Selection
For Each b In a.Rows
    If b.Height < 16 Then
        c = c & b.Row & ":" & b.Row & ","
    End If
Next
If Right$(c, 1) = "," Then c = Left$(c, Len(c) - 1)
Range(c).Select
End Sub

How can I pass the string (which outputs, e.g., "67:67,513:513,534:534") to Range in order to select the rows?

5
  • As I see it won't work only when all rows in Selection has height >= 16 and since c is empty Range(c).Select throws an error. Can you add MsgBox c just before Range(c).Select. What message would you get? Commented Mar 4, 2014 at 20:51
  • I used ActiveSheet.Range("C1").Value = c instead; prints 904:904,928:928,968:968,969:969,992:992,1035:1035. Commented Mar 4, 2014 at 20:53
  • What happend when code tries to evaluate Range(c).Select? Did you get any error? If yes, what is the error message? Commented Mar 4, 2014 at 20:55
  • It prints, Run-time error '1004': Method 'Range' of object '_Global' failed. Commented Mar 4, 2014 at 20:58
  • It looks like some sort of type mismatch Commented Mar 4, 2014 at 20:58

1 Answer 1

1

This may work for you:

Sub FindAndRemoveSmallRows()
Dim b As Range, c As Range
if typename(selection)<>"Range" then exit sub
For Each b In Selection.Rows
    If b.Height < 16 Then
        if c is nothing then 
            set c = b
        else
            set c = application.union(c, b)
        end if
    End If
Next
if not c is nothing then c.entirerow.Select
End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.