Solved

I keep screwing up vba code

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

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.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

739 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