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

x
?
Solved

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

Posted on 2015-01-12
5
Medium Priority
?
121 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
[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
  • 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 2000 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 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

715 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