Formatting an Excel document after creation with VBA

Hi

I am using Excel for creating offers and bills.
I'm really fast at it, too. But one thing is kind of tedious.

I have a formatting requirement:
Between each row that has text, there should be one row, and only one, that is empty.
The height of the row should be 15.

Unfortunately, I do not know how to keep the number of empty rows constant.
What's more, the empty rows should have the same height.

So, after creating the document, I would like to run a macro that makes sure that
1) omitted rows are inserted,
2) single empty rows with the wrong height adjusted, and
3) double or triple rows that are empty deleted.

So here's what I desire:

Here's sth bold
Here's an empty row. Height: 15
Here's some text
Here's an empty row. Height: 15
Here's some more text
Here's an empty row. Height: 15

What I may have is something like this:
Here's sth bold
Here's an empty row. Height: 30
Here's an empty row. Height: 15
Here's some text
Here's some more text
Here's an empty row. Height: 40

Is it possible to create a macro for this?
I know only some VBA and mostly from code that I got with the macro recorder and adapted.

Thanks!
Screenshot---18.04.2011---18-24-.png
speechrecAsked:
Who is Participating?
 
Saqib Husain, SyedEngineerCommented:
Try this macro
Sub altemptyrows()
For Each rw In ActiveSheet.UsedRange.Rows
If rw.Row > 1 And rw.Row < ActiveSheet.UsedRange.Rows.Count Then
    If WorksheetFunction.CountA(rw) = 0 Then
        Do While WorksheetFunction.CountA(rw.Offset(1, 0)) = 0
            rw.Offset(1, 0).Delete
            If WorksheetFunction.CountA(Range(Cells(rw.Row + 1, 1), Cells(ActiveSheet.Rows.Count, ActiveSheet.Columns.Count))) = 0 Then Exit Do
        Loop
            rw.RowHeight = 15
    Else
        If WorksheetFunction.CountA(rw.Offset(-1, 0)) > 0 Then
            rw.Insert
            rw.Offset(-1, 0).RowHeight = 15
        End If
    End If
End If
Next rw
End Sub

Open in new window

0
 
SiddharthRoutCommented:
>>s it possible to create a macro for this?
I know only some VBA and mostly from code that I got with the macro recorder and adapted.

Yes :)

If you can upload the file I will directly write a macro for that. That way, I'll get my references correct as well in one go :)

Sid
0
 
speechrecAuthor Commented:
ssagibh
This is quite good.
Is there any way to stop it after line 200?
I never go further than that at it doesn't need to loop all the way through.
0
 
Saqib Husain, SyedEngineerCommented:
Change

If rw.Row > 1 And rw.Row < ActiveSheet.UsedRange.Rows.Count Then

to

If rw.Row > 1 And rw.Row < 200 Then
0
 
speechrecAuthor Commented:
Thanks, that was it!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.