VBA hide rows with variable range

Is_REF

New Member
Joined
Feb 22, 2019
Messages
10
Hello!
I am very new with VBA, I will really appreciate some help :)
I have a list of 100 rows and I want to be able to show/hide only the rows that contains values (from row 5 to row "X"). I have an auxiliary cell "AV1" that counts the number of rows that contain values ("X"=N_Rows) (they will always be ordered for the blanks to be at the end). I also have cell K1 that is 0 when the full list is hidden or =100 when the list is shown.

Sub List()

Dim N_Rows As Long
Range("AV1").Value = N_Rows

If Range("K1").Value = 0 Then
Rows("5:" & N_Rows).EntireRow.Hidden = False
Else
Rows("5:" & N_Rows).EntireRow.Hidden = True
End If
End Sub

I am getting "Run-time error '13': Type mismatch" - What I am doing wrong?
Thanks for your help!
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
It must be the other way around

Code:
Sub List()


Dim N_Rows As Long

[COLOR=#0000ff]N_Rows = Range("AV1").Value [/COLOR]


If Range("K1").Value = 0 Then
Rows("5:" & N_Rows).EntireRow.Hidden = False
Else
Rows("5:" & N_Rows).EntireRow.Hidden = True
End If
End Sub


Try and tell me
 
Upvote 0
Change this line

Code:
Range("AV1").Value = N_Rows


To

Code:
N_Rows=Range("AV1").Value
 
Upvote 0
It must be the other way around

Code:
Sub List()


Dim N_Rows As Long

[COLOR=#0000ff]N_Rows = Range("AV1").Value [/COLOR]


If Range("K1").Value = 0 Then
Rows("5:" & N_Rows).EntireRow.Hidden = False
Else
Rows("5:" & N_Rows).EntireRow.Hidden = True
End If
End Sub


Try and tell me



Thanks a lot! :)

I have tried different things, finally works! :

Sub List()

Dim N_Rows As Integer
N_Rows = Range("AV1").Value + 4

If Range("K1").Value = 0 Then
Rows("5:" & N_Rows).EntireRow.Hidden = False
Else
Rows("5:" & N_Rows).EntireRow.Hidden = True
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

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