![]() |
How to code Macro for hiding rows
Hello!
I need help with some macro coding, as I am new to it. Here is the basic breakdown: I have 50 rows of data space. Some rows do not have date. I need to hide the rows which don't have data. If I could code it by dictation, I would say "If A2 is empty, hide the row. Do the same for A3 through A50" Any suggestions?? |
How to code Macro for hiding rows
Hi Catherine,
Try: '============= Public Sub Tester() Dim rng As Range Set rng = ActiveSheet.Range("A2:A50") '<<==== CHANGE On Error Resume Next rng.SpecialCells(xlBlanks).EntireRow.Delete On Error GoTo 0 End Sub '<<============= --- Regards, Norman "Catherine Bond" wrote in message ... Hello! I need help with some macro coding, as I am new to it. Here is the basic breakdown: I have 50 rows of data space. Some rows do not have date. I need to hide the rows which don't have data. If I could code it by dictation, I would say "If A2 is empty, hide the row. Do the same for A3 through A50" Any suggestions?? |
How to code Macro for hiding rows
Hi Catherine,
As you are not familiar with macros, you may wish to visit David McRitchie's 'Getting Started With Macros And User Defined Functions' at: http://www.mvps.org/dmcritchie/excel/getstarted.htm You might also look at David's tutorials page at: http://www.mvps.org/dmcritchie/excel....htm#tutorials The VBA tutorial information is towards the end of that section. --- Regards, Norman |
How to code Macro for hiding rows
One way:
Sub HideRows() Dim i As Long Application.ScreenUpdating = False For i = 2 To 50 If Range("A" & i).Value = "" Then Range("A" & i).EntireRow.Hidden = True End If Next 'i Application.ScreenUpdating = True End Sub Regards Trevor "Catherine Bond" wrote in message ... Hello! I need help with some macro coding, as I am new to it. Here is the basic breakdown: I have 50 rows of data space. Some rows do not have date. I need to hide the rows which don't have data. If I could code it by dictation, I would say "If A2 is empty, hide the row. Do the same for A3 through A50" Any suggestions?? |
How to code Macro for hiding rows
Hi Catherine,
rng.SpecialCells(xlBlanks).EntireRow.Delete Should read: rng.SpecialCells(xlBlanks).EntireRow.Hidden = True The first (erroneously) deletes the blank rows; the second hides these rows, as you requested! --- Regards, Norman "Norman Jones" wrote in message ... Hi Catherine, Try: '============= Public Sub Tester() Dim rng As Range Set rng = ActiveSheet.Range("A2:A50") '<<==== CHANGE On Error Resume Next rng.SpecialCells(xlBlanks).EntireRow.Delete On Error GoTo 0 End Sub '<<============= --- Regards, Norman |
All times are GMT +1. The time now is 05:20 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com