Solved

I keep screwing up vba code

Posted on 2014-12-22
3
121 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

821 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