Results 1 to 4 of 4

Thread: VBA Code - Error on Code - Where am I going wrong?

  1. #1
    Board Regular
    Join Date
    Jul 2018
    Location
    Auckland
    Posts
    308
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default VBA Code - Error on Code - Where am I going wrong?

    Hi,

    Can anyone please tell me what is wrong with my code below? It highlights the 3rd to last row, Me.CommandButton2.Visible = CBool(Target.Value = "YES")

    It says Run-time error '13': Type Mismatch

    Thank you!


    Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
            If Not Intersect(Target, Me.Range("F5")) Is Nothing Then
            Me.CommandButton1.Visible = CBool(Target.Value = "YES")
        End If
        
            If Not Intersect(Target, Me.Range("F8")) Is Nothing Then
            Me.CommandButton2.Visible = CBool(Target.Value = "YES")
        End If
        End Sub
    Last edited by tlc53; Sep 26th, 2019 at 09:43 PM.

  2. #2
    MrExcel MVP
    Join Date
    May 2009
    Posts
    16,590
    Post Thanks / Like
    Mentioned
    39 Post(s)
    Tagged
    9 Thread(s)

    Default Re: VBA Code - Error on Code - Where am I going wrong?

    I don't see anything wrong and cannot reproduce your error.
    Joe

    When I was a young man I knew everything. Now that I'm older, I realize I know very little, and what I do know, I tend to forget!

  3. #3
    Board Regular
    Join Date
    Sep 2013
    Location
    Blue Mountains, Australia
    Posts
    3,487
    Post Thanks / Like
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA Code - Error on Code - Where am I going wrong?

    Maybe Target contains more than one cell? You only need to test Range("F8").Value, not Target.Value

    Or maybe Target contains an error value?

  4. #4
    Board Regular
    Join Date
    Jul 2018
    Location
    Auckland
    Posts
    308
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA Code - Error on Code - Where am I going wrong?

    Quote Originally Posted by StephenCrump View Post
    You only need to test Range("F8").Value, not Target.Value
    Thank you Stephen. This was causing me a lot of grief but this comment fixed the error. Thank you!

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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