Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

I keep screwing up vba code

Posted on 2014-12-22
3
Medium Priority
?
135 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 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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 descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

885 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