Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

I keep screwing up vba code

Posted on 2014-12-22
3
Medium Priority
?
132 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 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