Solved

How would I code ElseIf statements to work on text instead of numbers (value)?

Posted on 2015-01-12
5
111 Views
Last Modified: 2015-01-12
Hi,

Below is the code that I use for cell visibility but it is only for value
Is there a way to get it to recognize text as well? So if, for example, A1='yes' then rows 2:5 are shown but if A1='' then rows 2:5 are hidden

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rngIntersect As Range
Set rngIntersect = Intersect(Target, Range("$I$12:$I$1500"))

If Not rngIntersect Is Nothing Then

    If Range("B23").Value = 0 And Range("B24").Value = 0 And Range("B25").Value = 0 Then
            'federal
            Rows("22:33").EntireRow.Hidden = True
        ElseIf Range("B23").Value > 0 Then
            Rows("22:24").EntireRow.Hidden = False
            Rows("32:33").EntireRow.Hidden = False
            Rows("25:31").EntireRow.Hidden = True
        ElseIf Range("B23").Value = 0 And Range("B24").Value > 0 Then
            Rows("22").EntireRow.Hidden = False
            Rows("23").EntireRow.Hidden = True
            Rows("24").EntireRow.Hidden = False
            Rows("25:31").EntireRow.Hidden = True
            Rows("32:33").EntireRow.Hidden = False
        ElseIf Range("B25").Value > 0 Then
            Rows("22").EntireRow.Hidden = False
            Rows("23:24").EntireRow.Hidden = True
            Rows("25:33").EntireRow.Hidden = False
        Else
            Rows("22:33").EntireRow.Hidden = False
        End If

    If Range("B42").Value = 0 And Range("B43").Value = 0 And Range("B44").Value = 0 Then
            'ma return
            Rows("41:52").EntireRow.Hidden = True
        ElseIf Range("B42").Value > 0 Then
            Rows("41:43").EntireRow.Hidden = False
            Rows("51:52").EntireRow.Hidden = False
            Rows("44:50").EntireRow.Hidden = True
        ElseIf Range("B42").Value = 0 And Range("B43").Value > 0 Then
            Rows("41").EntireRow.Hidden = False
            Rows("42").EntireRow.Hidden = True
            Rows("43").EntireRow.Hidden = False
            Rows("44:50").EntireRow.Hidden = True
            Rows("51:52").EntireRow.Hidden = False
        ElseIf Range("B44").Value > 0 Then
            Rows("41").EntireRow.Hidden = False
            Rows("42:43").EntireRow.Hidden = True
            Rows("44:52").EntireRow.Hidden = False
        Else
            Rows("41:52").EntireRow.Hidden = False
        End If
End If
End Sub

Open in new window

0
Comment
Question by:Boston617
  • 3
  • 2
5 Comments
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
Comment Utility
If A1="Yes"

If A1=""
0
 

Author Comment

by:Boston617
Comment Utility
I would not need to add .string or .text to the range?
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
Comment Utility
Sorry, it should have been

range("A1").value = "Yes"

range("A1").value = ""
0
 
LVL 43

Assisted Solution

by:Saqib Husain, Syed
Saqib Husain, Syed earned 500 total points
Comment Utility
.value applies to both text and numbers
0
 

Author Comment

by:Boston617
Comment Utility
oh really?! thank you!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

771 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

13 Experts available now in Live!

Get 1:1 Help Now