views:

26

answers:

1

My task is to get text to print and display though it is longer than the 409 point row show. The sheet I'm working on is a Destination sheet from a Source sheet that can change often, but generally only 1 of 15 cells present this problem. Cell parameters are fixed so I can't change font or column width. On a spreadsheet I've made a Macro that will insert one or more rows, merge the required cells and change the row height to increase the cell enough but what " IF ... END IF" can I use to find rows larger than 408 points to trigger the Macro? Using Excel 2007. Thanks.

A: 

Try recording a Macro and changing the size of a row. Then inspect the VBA code that the macro generates to see how the size of the Row is generated in code.

You'll notice that the VBA code doesn't use pixels, so you'll have to do a conversion to find the equivalent of 409 pixels. After that, you can use a loop to find all of the rows that have a cell height greater than a certain value:

Dim lng As Long
lng = 1
Do While Not IsEmpty(Range("A" & lng).Value)
  If Rows(lng).RowHeight >= 306.75 Then
    'Insert the code to add a new row here.  When looking at the '
    'code in your macro, you can replace the row number (e.g. the "18:18" in  '
    'Rows("18:18") with the counter variable, lng, like so: Rows(lng).... '
    'If you want the *following* row, use Rows(lng+1) instead.
    ''
    'I'm not sure of the command to insert a new row, but if you do insert a '
    'new row, watch your counter.  You may need to add an additional  '
    'lng = lng + 1 into your code to account for the newly added row.'
  End If
  lng = lng + 1
Loop
Ben McCormack
Excellent, thanks Ben. That got my macro to find all rows based on height. Now a follow up question: How do I get the macro to add a new row under each row over 409pts? My intent is to locate each row over 409, insert a row below it, change both rows to 409 high and merge the "over-texted" cell. I can do the add, size and merge, and your help got me to find each row but my macro wants to put the new row where I created (recorded) the macro, not under each found row. How do I change my " Rows("18:18").Select " to be " Rows(each one found).Select "?Thanks again.
Kirk
@Kirk see my additional comments in my answer. Basically, you can use variable names instead of the hardcoded row numbers from your macro. For example, in my example code, I used `Rows(lng)`, which uses the value for the `lng` variable to feed to the `Rows()` function. You may need to play with that number a little bit to make sure you're working with the Row.
Ben McCormack