Object required Error with 'If If Target.Address = "$K$65" Then

eli_m

Board Regular
Joined
Jun 2, 2022
Messages
129
Office Version
  1. 365
Platform
  1. Windows
Hi,

I am getting the below error:

1712735956646.png



With:
VBA Code:
Private Sub Worksheet_Change(ByVal Targer As Range)

If Target.Address = "$K$65" Then
    If Target.Value = "" Then
        Shapes.Range(Array("Step2")).Line.Visible = msoTrue
        Shapes.Range(Array("Step2.5")).Line.Visible = msoFalse
        Shapes.Range(Array("Step3")).Line.Visible = msoFalse
    Else
    If Target.Value > 0 Then
        Shapes.Range(Array("Step2")).Line.Visible = msoFalse
        Shapes.Range(Array("Step2.5")).Line.Visible = msoTrue
        Shapes.Range(Array("Step3")).Line.Visible = msoTrue
        End If
    End If
End If

End Sub

It's saying it has something do with this:
1712736066322.png


But I can't figure it out.

I have tested the cell with:
=IF($K$65="","EMPTY",IF($K$65>0,"YES",""))

And it shows EMPTY when there's nothing there and "YES" if the number is above 0 so it seems to work there but not in VBA.

Thank you in advance!
 
So
You need the Worksheet_Calculate event, not the Change event, or if K15:K64 are literal values, monitor those cells in the change event, not the formula cell.
Thanks for your help but I am unsure where to even start. I did the change event and got:
1712827950176.png


Code I am using is:
VBA Code:
Private Sub Worksheet_Calculate(ByVal Target As Range)
If Target.Address = "$K$65" Then
    If Target.Value = "" Or Target.Value < 1 Then
        Me.Shapes("Step2").Visible = msoTrue
        Me.Shapes("Step2.5").Visible = msoFalse
        Me.Shapes("Step3").Visible = msoFalse
    Else
    If Target.Value > 0 Then
        Me.Shapes("Step2").Visible = msoFalse
        Me.Shapes("Step2.5").Visible = msoTrue
        Me.Shapes("Step3").Visible = msoTrue
        End If
    End If
End If
End Sub


I then tried:
If Target.Address = "K15:K64" Then
and that didn't work either
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
The calculate event doesn't provide a Target argument, so it would just be:

VBA Code:
Private Sub Worksheet_Calculate()
dim formulaCell as Range
set formulaCell = Range("K65")

    If formulaCell.Value = "" Or formulaCell.Value < 1 Then
        Me.Shapes("Step2").Visible = msoTrue
        Me.Shapes("Step2.5").Visible = msoFalse
        Me.Shapes("Step3").Visible = msoFalse
    ElseIf formulaCell.Value > 0 Then
        Me.Shapes("Step2").Visible = msoFalse
        Me.Shapes("Step2.5").Visible = msoTrue
        Me.Shapes("Step3").Visible = msoTrue
    End If

End Sub

I don't really understand your criteria though as they overlap.
 
Upvote 1
The calculate event doesn't provide a Target argument, so it would just be:

VBA Code:
Private Sub Worksheet_Calculate()
dim formulaCell as Range
set formulaCell = Range("K65")

    If formulaCell.Value = "" Or formulaCell.Value < 1 Then
        Me.Shapes("Step2").Visible = msoTrue
        Me.Shapes("Step2.5").Visible = msoFalse
        Me.Shapes("Step3").Visible = msoFalse
    ElseIf formulaCell.Value > 0 Then
        Me.Shapes("Step2").Visible = msoFalse
        Me.Shapes("Step2.5").Visible = msoTrue
        Me.Shapes("Step3").Visible = msoTrue
    End If

End Sub

I don't really understand your criteria though as they overlap.
Sadly that didn't work. K15:K64 are literal values how could I use that?
 
Upvote 0
Is K65 definitely the right cell? You have P12 in the picture but K65 in the code you posted.
 
Upvote 0

Forum statistics

Threads
1,215,203
Messages
6,123,627
Members
449,109
Latest member
Sebas8956

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top