We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Formatting an Excel document after creation with VBA

speechrec
speechrec asked
on
Medium Priority
297 Views
Last Modified: 2012-05-11
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
Comment
Watch Question

>>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
Engineer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

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.
Saqib HusainEngineer
CERTIFIED EXPERT

Commented:
Change

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

to

If rw.Row > 1 And rw.Row < 200 Then

Author

Commented:
Thanks, that was it!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.