column width and row height formatting, & IF

S

SteveDB1

Hi all.
I've recorded a macro, and in part of it I want to look at a specific group
of columns' widths.
I.e., I want to know if a column is less than a standard, or predetermined
width, and if so, delete that column. Someone has placed a series of "buffer"
columns to act as spacers, and they're unnecessary for our purposes, so I
want to delete them, and doing this by hand is really time consuming.
I've read some of the posts, and I'm wondering if the following will work.

dim MyCol as range

if MyCol.columnwidth<X 'where X is my choice of width.

myCol.select

Selection.Delete Shift:=xlToLeft

end if

Similarly, I want to do something identical with row heights.
would
dim MyRow as range

if MyRow.rowheight < Y 'where Y is my predetermined height value

MyRow.select
Selection.Delete Shift:=xlUp
end if


Thanks for your responses.
Best.
 
R

Rick Rothstein \(MVP - VB\)

Give this code a try (substitute the width you want to compare to for the
8.43 width I used)...

Sub RemoveNarrowColumns()
Dim X As Long
For X = Columns.Count To 1 Step -1
If Columns(X).ColumnWidth < 8.43 Then Columns(X).Delete
Next
End Sub

Rick
 
R

Rick Rothstein \(MVP - VB\)

Sorry, missed your 2nd question regarding short rows. Give this macro a try
for them...

Sub RemoveShortRows()
Dim X As Long
For X = Rows.Count To 1 Step -1
If Rows(X).RowHeight < 12.75 Then Rows(X).Delete
Next
End Sub

Rick
 

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