5
I’m creating an automated report template that fits onto one page. This report includes bullet points and a chart. Because of a presentation request I need to make sure the chart always sits the same distance under the last bullet point. Unfortunately, there can be 7 bullet points or 2. So automating this has become troublesome.
See image below, but my thinking is:
- Specify a range (B11:B17)
- Go to the bottom of that range and work up
- Find empty cells in that range and delete entire row (issue 1)
- Update the range variable to accommodate the change (unable to do)
- Carry out the previous steps
- Retrieve original range size and re-insert those rows where it should be
- Go back to my original procedure to populate the bullets and then start at Step 1 again
VBA is something I struggle with, but find myself using more and more. I have searched and tried different ways to create a range and delete empty cells/rows. Some of them were dangerously bad. I’m starting with this simple code below now, but it’s not working:
Set MyFullRange = Range("B11:B17")
MyFullRange.Select
For CellRange = 1 To MyFullRange.Rows.Count
If MyFullRange(CellRange).End(xlUp).Row = "" Then
MyFullRange(CellRange).EntireRow.Delete xlShiftUp
End If
Next CellRange
My issues
- The bullet rows are populated by referring to another sheet (=ProjectBullet_1, =ProjectBullet_2, etc.). Therefore I’m having trouble recognising the empty cell and deleting the row accordingly.
- Reinserting the rows so that it’s back to my original template structure. (see possible alternative idea below)
- The bulleted rows appear in a certain part of the template $B$20:$B:$26. (below and above other populated rows) and previous attempts to delete rows have resulted in other empty rows being deleted.
Would it be easier (especially for step 6) if I simply copied the template sheet, called it something else and carried Steps 1 to 5 on the copy, deleting the copy once I exported it?
I know I need to break this issue down into pieces, but I'm struggling with the first piece.
I hadn't even thought about hiding them! That would help me avoid a few difficult steps. Thanks. – RocketGoal – 2016-11-14T11:43:32.757
The part of the code
+ 10 To 11 Step -1
. What's the reason for this? Understand the -1 principle but why10 to 11
? – RocketGoal – 2016-11-14T11:52:26.270thisrange.Rows.Count
gives the number of rows (7 for example), I'm adding 10 to start at row 17. I know it can be done better but I was doing it as a quick test. – jcbermu – 2016-11-14T12:11:10.977vbnullstring
is pretty great.. – Raystafarian – 2016-11-14T12:51:08.880Worked perfectly. Your hidden idea was a real "Doah" moment for me :) Thanks. – RocketGoal – 2016-11-15T14:23:55.563