Thread: Explain Macro?
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
JE McGimpsey JE McGimpsey is offline
external usenet poster
 
Posts: 4,624
Default Explain Macro?

What "bugs" you about the code, Robert?

Your alternative unhides rows outside the range of interest (presumably
the reason for having an unhiderange at all); requires significantly
more range resolution than a For Each...Next; adds a couple hundred
calculation cycles; and adds unasked-for user intervention. In addition,
it gives a run-time error if there are no blank (or non-blank) cells in
the range of interest.

Disclaimer: TomO and I (independently) came up with the subject code, so
I'm hardly unbiased.

BTW, it only takes one minor modification to your code to account for B3:


For y = x + (x = 4) to x + 17


In article ,
"Robert McCurdy" wrote:

I really don't like the way the first one is written.
Its bugging me so I had to do this.


Sub MyPPp()
Dim x As Long, y As Long, Str As String
Application.Cells.Rows.Hidden = False
Str = MsgBox("to Hide blanks pick YES, to Hide content pick NO",
vbYesNoCancel)
If Str = vbCancel Then End
For x = 4 To 285 Step 24
For y = x To x + 17
If Str = vbYes Then
If Cells(y, 2) = "" Then Cells(y, 3) = "=1/0"
Else
If Cells(y, 2) < "" Then Cells(y, 3) = "=1/0"
End If
Next y
Next x
Range("C4:C285").SpecialCells(xlCellTypeFormulas, xlErrors).EntireRow.Hidden
= True
Columns(3).ClearContents
End Sub


If you already have data in your C column, can you just insert a new column
and hide it?
This one I hope is a little more clear to understand.
I know it supposed to start in B3, but the above wouldn't work without a lot
more code just to deal with one cell. You could just
as easily do whatever manually to B3.