Cannot hide a row for a specific cell in VBA. I suppose that I need a second set of eyes?

OaklandJim

Well-known Member
Joined
Nov 29, 2018
Messages
863
Office Version
  1. 365
Platform
  1. Windows
Looping cells in a one column range containing seven cells. If a cell's content Len is 0 or 1 then hide its row. That way empty rows are not shown (are hidden) in the range of seven cells.

Beyond basic! But I cannot get
VBA Code:
rCell.EntireRow.Hidden = True
to work where rCell is a single celled range object used to iterate through the seven cells. What might I try?

Here are the seven cells to look into. They are the seven cells below the header.

Cell Formulas
RangeFormula
D7:D9,D12:D13D7=INDEX(Providers!ProviderNames,rrIndex)&CHAR(10) & INDEX(Providers!PlanNames,rrIndex) & IF(INDEX(Providers!Plan_Types,rrIndex)="", "", IF(INDEX(Providers!PlanNames,rrIndex) = "", "", ", ") & INDEX(Providers!Plan_Types,rrIndex))
D10D10=INDEX(Providers!ProviderNames,rrIndex) & CHAR(10) & INDEX(Providers!PlanNames,rrIndex) & IF(INDEX(Providers!Plan_Types,rrIndex)="", "", IF(INDEX(Providers!PlanNames,rrIndex) = "", "", ", ") & INDEX(Providers!Plan_Types,rrIndex))
Named Ranges
NameRefers ToCells
Providers!Plan_Types=Providers!$E$5:$E$10D12:D13, D7:D10
Providers!PlanNames=Providers!$D$5:$D$10D12:D13, D7:D10
Providers!PlanTypes=Providers!$E$5:$E$10D12:D13, D7:D10
Providers!ProviderNames=Providers!$C$5:$C$10D12:D13, D7:D10
rrIndex=Result!$B7D7


VBA Code:
Sub CopyTable()

    Dim rPlanNamesCells As Range
   
    Dim rCell As Range
   
    Dim iCell As Long
   
'   Set variable rPlanNamesCells to "point" to cells in results table
'   containing plan names in Result sheet. Note that this includes the
'   cell containing the label for options with "special" characteristics.
'   Note hardwired count of rows in the table (7).
    Set rPlanNamesCells = [Result].Range("Header_ProviderName").Cells(2).Resize(7)
   
'Shows correct range.
Debug.Print "rPlanNamesCells = " & rPlanNamesCells.Address

'For indexing cells for debugging.
iCell = 0

    For Each rCell In rPlanNamesCells
 
Debug.Print Chr(10)

'Increment cell index # for debugging.
iCell = iCell + 1
   
'       Hide empty rows. A cell may contain no characters or one character
'       (a line feed character).
        If Trim(rCell.Value) = "" Or Len(rCell) = 1 _
         Then
            Debug.Print "cell " & iCell & ". " & "rCell.value is nothing"
           
'           Hide the empty cells' row.
            rCell.EntireRow.Hidden = True
       
        Else
       
            Debug.Print "cell " & iCell & ". " & "cell value = " & rCell.Value
       
        End If
   
    Next rCell
   
'   (re)Expose all rows in the results table.
    rTable.EntireRow.Hidden = False
   
End Sub
 
May be something like this,
VBA Code:
Sub CopyTable()
    Dim ws As Worksheet
    Dim rPlanNamesCells As Range
    Dim rCell As Range

    Set ws = Worksheets("Result")
    Set rPlanNamesCells = ws.Range("Header_ProviderName").Cells(2).Resize(7)

    For Each rCell In rPlanNamesCells
        If Trim(rCell.Value) = "" Or Len(rCell.Value) = 1 Then
            rCell.EntireRow.Hidden = True
        End If
    Next rCell
End Sub
 
Upvote 0
Thanks for the response but that facet of my code is correct so no need to change it.

Here is what I did. I was hiding rows then reexposing them in the same sub. So, row hiding was working as coded originally. It's just that I reexposed the rows so could not see rows that are hidden.

This is a true brain fart.

Issue solved.
 
Upvote 0
Solution

Forum statistics

Threads
1,226,771
Messages
6,192,919
Members
453,767
Latest member
922aloose

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top