Operator syntax - VBA problem

  • Thread starter Thread starter laserface
  • Start date Start date
L

laserface

Sorry, this is probably a daft question but its driving me nuts.

I want to write a routine where a picture becomes visible or no
depending on the magnitude of a number in a particular cell.

The following works ok on a single greater than condition
The image being contained in an image control obviously.

If Sheet5.Cells(6, 11) > 40 Then
Sheet5.Image1.Visible = True
Else
Sheet5.Image1.Visible = False
End If

However i want to use the "OR" function to make the picture visible i
the magnitude of a number in a particular cell falls between
particular range so i think the code should be something like


If Sheet5.Cells(6, 11) > 40 or < 300 Then
Sheet5.Image1.Visible = True
Else
Sheet5.Image1.Visible = False
End If


But the line > 40 or < 300 does not work and i cant figure out why.

Any and all suggestions greatfully recieved !

regards
LaserFac
 
Hi Laserface,

Try:

If Sheet5.Cells(6, 11) > 40 And _
Sheet5.Cells(6, 11) < 300 Then
 
Hi Grey Newt,
If Sheet5.Cells(1, 1).Value > 40 Or Sheet1.Cells(6, 11).Value < 300 Then

I think that you need to replace Or with And

As written, your If condition will always return true.
 
An oft-overlooked language capability is how booleans work.

Sheet5.Image1.Visible = _
Sheet5.Cells(6, 11) > 40 and Sheet5.Cells(6, 11) < 300
--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 
Outstanding response on this forum.
I managed to resolve the problem after referrring to all your answer
using AND and OR operators.

Many thanks to you all for the excellent and rapid assistance.

regards,
Laserfac
 

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