+ Reply to Thread
Results 1 to 4 of 4

If And function in VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    05-04-2015
    Location
    South Africa
    MS-Off Ver
    office for Mac
    Posts
    97

    If And function in VBA

    Hi All,

    I hope you are well. I hope you can assists me with the following:

    I used to have a code running from one cell selection and it looked like the following:

    Option Explicit
    
    Public sheetactivated As Boolean
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Address = "$C$103" Then
            If Range("'Client info'!C103").Value = "Large Enterprise" Then
                Sheets("Skills Spend & Learnerships").Rows("1:153").EntireRow.Hidden = False
                Sheets("Skills Spend & Learnerships").Rows("154:422").EntireRow.Hidden = True
                End If
        End If
        If Target.Address = "$C$102" Then
            If Range("'Client info'!C102").Value = "Yes" Then
                Sheets("Skills Spend & Learnerships").Rows("135").EntireRow.Hidden = False
                Sheets("Skills Spend & Learnerships").Rows("140").EntireRow.Hidden = True
                Sheets("Skills Spend & Learnerships").Rows("230").EntireRow.Hidden = False
                Sheets("Skills Spend & Learnerships").Rows("235").EntireRow.Hidden = True
            ElseIf Range("'Client info'!C102").Value = "No" Then
            Sheets("Skills Spend & Learnerships").Rows("135").EntireRow.Hidden = True
            Sheets("Skills Spend & Learnerships").Rows("140").EntireRow.Hidden = False
            Sheets("Skills Spend & Learnerships").Rows("230").EntireRow.Hidden = True
            Sheets("Skills Spend & Learnerships").Rows("235").EntireRow.Hidden = False
            End If
        End If
    End Sub
    Te latter part of the code I've added with the introduction of a new function, however it does not work as some lines will be unhidden due to the latter part of the code. Now I was wondering if their is not a code similar to that of a "If AND"Function? I hope I make sense. Any help would be greatly appreciated.
    Last edited by ramatthews; 10-08-2019 at 06:34 AM.

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,462

    Re: If And function in VBA

    Please reformat your code, it's partly unreadable

  3. #3
    Registered User
    Join Date
    05-04-2015
    Location
    South Africa
    MS-Off Ver
    office for Mac
    Posts
    97

    Re: If And function in VBA

    Hi, Thank you for your feedback. I have done as requested.

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,505

    Re: If And function in VBA

    Perhaps...Unless...Are you wanting code to run depending on both C102 & C103 entries...
    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim ws As Worksheet: Set ws = Sheets("Skills Spend & Learnerships")
    If Not Intersect(Target, Range("C103")) Is Nothing Then
        Application.EnableEvents = False
        If Target = "Large Enterprise" Then
            With ws
                .Rows("1:153").Hidden = False
                .Rows("154:422").Hidden = True
            End With
        End If
        Application.EnableEvents = True
    End If
    If Not Intersect(Target, Range("C102")) Is Nothing Then
         Application.EnableEvents = False
         Select Case Target
            Case Is = "Yes"
            With ws
                .Range("135:135,230:230").EntireRow.Hidden = False
                .Range("140:140,235:235").EntireRow.Hidden = True
            End With
            Case Is = "No"
            With ws
                 .Range("135:135,230:230").EntireRow.Hidden = True
                .Range("140:140,235:235").EntireRow.Hidden = False
            End With
        End Select
        Application.EnableEvents = True
    End If
    End Sub
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. COUNTUNIQUE Function in Google Sheets; Excel lacks a direct counterpart to this function?
    By PivotTablePSHomage in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-18-2018, 05:27 AM
  2. Replies: 3
    Last Post: 08-14-2017, 06:26 AM
  3. Calling function inside function. (aka nested function)
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-02-2015, 05:58 AM
  4. Replies: 13
    Last Post: 04-08-2014, 05:46 AM
  5. index function error using match function to get data from a cell in an array
    By mabildgaard in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-17-2013, 02:21 AM
  6. Replies: 1
    Last Post: 03-21-2012, 11:22 AM
  7. Replies: 2
    Last Post: 03-20-2009, 01:29 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1