Solved

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

Posted on 2015-01-12
5
116 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
ID: 40545192
If A1="Yes"

If A1=""
0
 

Author Comment

by:Boston617
ID: 40545240
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
ID: 40545246
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
ID: 40545247
.value applies to both text and numbers
0
 

Author Comment

by:Boston617
ID: 40545252
oh really?! thank you!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
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…

816 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

11 Experts available now in Live!

Get 1:1 Help Now