Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2013
    Posts
    1

    Unanswered: Private Sub VBA AND function

    I can not get my AND function to work in a Private Sub:

    Private Sub Worksheet_Change(ByVal Target As Range)
    'Freeze screen while updating
    Application.ScreenUpdating = False

    If Target.Value(D44) = "YES" AND Target.Value(D45) = "YES" Then
    Rows("46:47").EntireRow.Hidden = False
    Range("D45").Select
    Else
    Rows("46:47").EntireRow.Hidden = True
    End If

    'Unfreeze screen
    Application.ScreenUpdating = True
    End Sub

    Please help.

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    What's not working?
    Any error messages?
    George
    Home | Blog

  3. #3
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Hi

    Don't know exactly what you want but this would seem to do it
    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
    Application.ScreenUpdating = False
    
    If Range("D44") = "YES" And Range("D45") = "YES" Then
        Rows("46:47").EntireRow.Hidden = False
        Range("D45").Select
    Else
        Rows("46:47").EntireRow.Hidden = True
    End If
    
    Application.ScreenUpdating = True
    
    End Sub
    ??

    The 'Target' argument referes to the worksheet's active cell (that has been changed) not the worksheet itself.

    HTH


    MTB

Tags for this Thread

Posting Permissions

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