excel if Range a1>a2

  • Thread starter Thread starter Magoo
  • Start date Start date
M

Magoo

Does any one know how to do this using vba.

I would like to have an if statement that is similar to this.

If Range("C8") > Range("C16") Then
ActiveSheet.Shapes("Oval 806").Select
Selection.ShapeRange.Line.Visible = False
End If

This will not work Please help...

Thanks
 
Just remove ShapeRange from your code.

Using a variable
Sub try()
Dim sh As Shape
Set sh = ActiveSheet.Shapes("Oval 806")
If Range("C8") > Range("C16") Then
sh.Line.Visible = False
End If
Set sh = Nothing
End Sub

Not using a variable
Sub tryAgain()
If Range("C8") > Range("C16") Then
ActiveSheet.Shapes("Oval 806") _
.Line.Visible = False
End If
End Sub
 
Code works fine as-is for me...

Is your worksheet unprotected?

Personally, I'd forego the selection and use

With ActiveSheet
If .Range("C8").Value > .Range("C16").Value Then
.Shapes("Oval 806").Line.Visible = False
End If
End With

or even use a toggle (which would make the line visible again if C16<=C8)

With ActiveSheet
.Shapes("Oval 806").Line.Visible = _
.Range("C8").Value <= .Range("C16").Value
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top