Delete Row Based On Row Height

T

theargus

Greetings.

I am attempting to create a macro which will automatically delete
entire rows based on height.

For example, I have a worksheet which contains rows of two different
heights. I need a script which will delete every row with a height of
27.75

I have a limited knowledge of VBA and am having difficulty creating
this macro.

Any and all help is sincerely appreciated.

Thanks in advance!


- Kobi
 
N

Nick Hodge

Kobi

Try this

Sub deleterowwith2775()
Dim llastrow As Long, x As Long
llastrow = Range("A65536").Row
For x = llastrow To 1 Step -1
If Range("A" & x).RowHeight = 27.75 Then
Range("A" & x).EntireRow.Delete
End If
Next x
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(e-mail address removed)
 
C

Charles Harmon

Hi,

Something like:
If ActiveCell.RowHeight = 22.5 Then ActiveCell.EntireRow.Delete
HTH

Charles
 
A

anonymousA

Hi

write down those instructions in a module of your VBA project

Sub deleterow()

For I = 65536 To 1 Step -1
If Cells(I, 1).RowHeight = 27.75 Then Cells(I, 1).EntireRow.Delete
Next

End Sub

All your spreadsheet will be scanned.

so long
 
A

anonymousA

Hi,

in your code, it's not really necessary to add "llastrow" because for sure
65536 is definetely the last row of a spreadsheet .
If you want to speed up your code, it would be interesting to determine
which row is the last one in a specific column.. According to this, you
could write ( but there're other solutions)
llastrow=range("A655536").end(xlup).row

Friendly,

So long
 
T

theargus

THANKS for the quick responses all!

I am using anonymousA's "deleterow" code and am having trouble getting
it work properly the worksheet I mentioned earlier - it runs, does not
error out, and does not delete the rows it is supposed to - it seems to
not do anything.

However, I copied and pasted the main worksheet into a NEW worksheet,
adjusted some of the row heights to 27.75 in the new worksheet, ran the
macro, and it did the job perfectly.

So now, a new question: why doesn't it work properly in the main
worksheet? Perhaps some attributes need to be altered in the main
worksheet so that it can work properly?

Some background: the main worksheet originated from a report
generating program called Impromptu. Impromptu allows you to save the
report as an .XLS file, which I did.

In addition: both worksheets I am referring to are in the same
workbook.

Any ideas?


THANKS AGAIN!

- Kobi
 
A

anonymousA

sorry, Kobi, but I don't know why it's not running on your main worksheet as
I can't how this one's built.
 
N

Nick Hodge

AA

That's actually a typo, it was meant to be

lLastRow=Range("A65536").End(xlUp).Row

Type it so many times I'm getting lazy, sorry to all

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(e-mail address removed)
 
G

Guest

When you said you made some changes to the "Test" wbk, What changes?
Specifically, did you change any heights?

If not, this is a guess: the report generator may have made the row height
something like 27.75443 which is rounded off when you look at the height.

If such is the case you might try something like

.rowheight>26

in your if statement.
 
T

theargus

gocush said:
If not, this is a guess: the report generator may have made the row height
something like 27.75443 which is rounded off when you look at the height.

If such is the case you might try something like

.rowheight>26

in your if statement.
Gocush,

THAT DID IT!

Thanks so much!


Impressed,

- Kobi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top