Row value using a variant

Red over White

Board Regular
Joined
Jul 16, 2011
Messages
123
Office Version
  1. 365
Platform
  1. MacOS
I am trying to hide rows where the cells value in each of the cells is ErrNA for the cells in columns B to F, and then repeat the exercise over a number of rows. If any cell within B to F is not ErrNA (it will be a number) then I don't want to hide the row.

The program doesn't like the red line, and possibly not the following line. The program works if I replace RowVar(j) with the actual row number, but I would prefer not to have to write out this line numerous times to get the desired effect.

Where am I going wrong?

Sub Graphic2022()

Application.ScreenUpdating = False

Sheets("Graphic").Activate

Rows("2:100").EntireRow.Hidden = False

Dim j As Integer
Dim RowVar As Variant
RowVar = Array("2", "3", "4", "5", "6", "7", "8", "9")

For j = 0 To 7
If Cells(RowVar(j), 2).Value = CVErr(xlErrNA) And Cells(RowVar(j), 3).Value = CVErr(xlErrNA) And Cells(RowVar(j), 4).Value = CVErr(xlErrNA) And Cells(RowVar(j), 5).Value = CVErr(xlErrNA) And Cells(RowVar(j), 6).Value = CVErr(xlErrNA) Then
Rows(RowVar(j) & ":" & RowVar(j)).EntireRow.Hidden = True
End If
Next j

End sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Could you have any errors on those rows which are not #N/A?
 
Upvote 0
This is the relevant extract of the sheet

Graphic.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABAC
1201820192020202120222003200420052006200720082009201020112012201320142015201620172018201920202021202220232024
2Area 124,476.0324,811.6924,225.2720,509.40#N/A20,044.8220,178.4620,954.0321,329.9722,237.1822,673.7923,342.0523,627.5923,924.7024,069.4024,023.4623,944.4624,026.5025,001.3824,426.5024,476.0324,811.6924,225.2720,509.40#N/A#N/A#N/A
3Area 2#N/A#N/A#N/A5,432.9816,210.61#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A5,432.9816,210.61#N/A#N/A
4Area 3#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A
5Area 42,878.603,824.803,544.583,395.241,667.031,734.511,698.001,975.743,319.762,880.103,336.293,799.893,750.032,609.064,957.983,254.333,346.023,595.732,940.623,325.662,878.603,824.803,544.583,395.241,667.03#N/A#N/A
6Area 54,664.505,907.685,812.475,145.703,976.591,001.60926.211,012.451,083.261,127.081,449.081,523.401,339.741,511.081,565.671,600.601,672.181,888.172,157.262,689.224,664.505,907.685,812.475,145.703,976.59#N/A#N/A
7Area 61,889.641,624.342,584.855,030.442,424.68727.54777.491,284.678.29132.70374.35140.929,224.542,335.922,435.592,747.753,321.143,642.693,764.804,607.831,889.641,624.342,584.855,030.442,424.68#N/A#N/A
8Area 7#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A389.99#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A
9Area 8#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A138.06276.18#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/A
10Area 9#N/A#N/A#N/A#N/A99.31#N/A#N/A#N/A99.31#N/A#N/A
11Area 10#N/A37.5030.002.00#N/A37.5030.002.00#N/A#N/A#N/A
12
Graphic
Cell Formulas
RangeFormula
B1:E1B1=C1-1
I1:AC1I1=H1+1
B2:F11B2=IF(LOOKUP(B$1,D$1:AE$1,D2:AE2)=0,NA(),LOOKUP(B$1,D$1:AE$1,D2:AE2))
H3:W3H3=IFERROR(IF(MAX(INDIRECT(H1&"!h4:h15"))=0,NA(),MAX(INDIRECT(H1&"!h4:h15"))-MAX(INDIRECT(H1&"!i4:i15"))),NA())
H4:W4H4=IFERROR(IF(OR(H1<2022,MAX(INDIRECT(H1&"!F4:F15"))=0),NA(),MAX(INDIRECT(H1&"!F4:F15"))-MAX(INDIRECT(H1&"!G4:G15"))),NA())
H8H8=NA()
 
Upvote 0
In that case try it like this
VBA Code:
If IsError(Cells(RowVar(j), 2).Value) And IsError(Cells(RowVar(j), 3).Value) And IsError(Cells(RowVar(j), 4).Value) Then
   Rows(RowVar(j)).EntireRow.Hidden = True
End If
I've done the 1st 4 cols as an example
 
Upvote 0
Solution
Hi,
try this update to your code & see if does what you want

VBA Code:
Dim ErrorCount As Long, r As Long, c As Long
    For r = 9 To 2 Step -1
     ErrorCount = 0
     For c = 2 To 6
        If Application.IsNA(Cells(r, c).Value) Then ErrorCount = ErrorCount + 1
     Next c
        Rows(r).EntireRow.Hidden = ErrorCount = 5
    Next r

Dave
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
Thanks Dave, I hadn't seen your solution until after my previous posting. It also works, and has a certain symmetry which my original attempt lacked. I will doubtless return to yours when developing other macros.
 
Upvote 0
No worries & appreciate feedback - you found a solution which is what matters - glad we were able to help.

Dave
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,680
Members
449,116
Latest member
HypnoFant

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