Solved

I keep screwing up vba code

Posted on 2014-12-22
3
114 Views
Last Modified: 2014-12-22
Hi, I can't seem to get this code to work (it was working fine before when I only had two Ifs). Can you point out what I'm doing wrong?

Private Sub Worksheet_SelectionChange(ByValue Target As Range)

If Not Intersect(Target, Range("$A$12:$A$1500")) Then

    If Range("C26").Value = 0 Then
        Rows("26:29").EntireRow.Hidden = True
    Else
        Rows("26:29").EntireRow.Hidden = False
    End If
    
    If Range("C25").Value = 0 Then
        Row("25").EntireRow.Hidden = True
    Else
        Row("25").EntireRow.Hidden = False
    End If
    
    If Range("C34").Value = 0 Then
        Rows("34:37").EntireRow.Hidden = True
    Else
        Rows("34:37").EntireRow.Hidden = False
    End If
    
    If Range("C33").Value = 0 Then
        Row("33").EntireRow.Hidden = True
    Else
        Row("33").EntireRow.Hidden = False
    End If
    
End Sub

Open in new window

0
Comment
Question by:Boston617
  • 2
3 Comments
 
LVL 59

Expert Comment

by:Saurabh Singh Teotia
ID: 40513061
Change this line...

If Range("C33").Value = 0 Then
        Row("33").EntireRow.Hidden = True
    Else
        Row("33").EntireRow.Hidden = False
    End If

Open in new window


With this..

If Range("C33").Value = 0 Then
        Rows("33").EntireRow.Hidden = True
    Else
        Rows("33").EntireRow.Hidden = False
    End If

Open in new window


Saurabh..
0
 
LVL 59

Accepted Solution

by:
Saurabh Singh Teotia earned 500 total points
ID: 40513068
In additional this line also need to be changed...

If Range("C25").Value = 0 Then
        Row("25").EntireRow.Hidden = True
    Else
        Row("25").EntireRow.Hidden = False
    End If

Open in new window


To this..

If Range("C25").Value = 0 Then
        Rows("25").EntireRow.Hidden = True
    Else
        Rows("25").EntireRow.Hidden = False
    End If

Open in new window


As soon you add s in the same it will work..
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 40513074
This line:
If Not Intersect(Target, Range("$A$12:$A$1500")) Then

Open in new window

should also be:
If Not Intersect(Target, Range("$A$12:$A$1500")) Is Nothing Then

Open in new window

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now