Consulting

Results 1 to 4 of 4

Thread: Have worksheet refresh only for changes in certain cells

  1. #1
    VBAX Regular
    Joined
    Nov 2009
    Posts
    13
    Location

    Have worksheet refresh only for changes in certain cells

    Hi, I need help with changing the below code so the macro doesn't activate every time ANY cell is changed in the worksheet. I only need it to refresh the worksheet if the value in C5 changes. Right now it's really annoying because every cell I change will make the macro run again and throws me back to the top of the worksheet which is really inconvenient. Thanks!

    [VBA]
    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    If Range("C5").Value = "No" Then
    Rows("122:152").Select
    Selection.EntireRow.Hidden = True
    Range("C5").Select
    ElseIf Range("C5").Value = "Yes" Then
    Rows("122:152").Select
    Selection.EntireRow.Hidden = False
    Range("C5").Select
    End If
    [/VBA]

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Greetings echane,

    Try:
    [vba]
    Option Explicit

    Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Count = 1 And Target.Address = "$C$5" Then
    If Range("C5").Value = "No" Then
    Rows("122:152").EntireRow.Hidden = True
    Range("C5").Select
    ElseIf Range("C5").Value = "Yes" Then
    Rows("122:152").EntireRow.Hidden = False
    Range("C5").Select
    End If
    End If
    End Sub
    [/vba]

    Hope that helps,

    Mark

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Simpler

    [vba]

    Option Explicit

    Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Count = 1 And Target.Address = "$C$5" Then
    Me.Rows("122:152").Hidden = Target.Value = "No"
    End If
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Regular
    Joined
    Nov 2009
    Posts
    13
    Location
    Thank you! You are all amazing! I'm learning things kinda bit by bit and this forum helps me out so much with that.

Posting Permissions

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