using `if` a value is between

  • Thread starter Thread starter FennisDuck
  • Start date Start date
F

FennisDuck

I am using zz as my variable
what I want to do is
if zz is between 7 and 10 then print out a range within a sheet
is the print range line correct ????????
any assistance appreciated

If ZZ = >1 or < =7 Then ' check value of zz
Range("A2:G36").PrintOut.SelectedSheets ' Print selected range

If ZZ > 8 or < 14Then
Range("A2:G36").PrintOut.SelectedSheets
 
You will need to use AND and get the operators in the correct syntax:

If zz >=1 And zz <= 7 Then
etc

which means if zz is between 1 and 7 (inclusive) then do something ...

Hope this helps.

Pete
 
Maybe you want:

Activesheet.Range("A2:G36").PrintOut

And you seem to be printing the same range no matter what your value in zz is.
(1 through 14).
 
Thank you
Pete Uk and Dave Peterson
in respect of the range being the same unfortunately one of the downsides of
copy `n` paste.
Once again thankyou for taking the time to look and reply with respective
formulas
 
Sorry Pete UK
It will only print range when zz is between 1 & 7 anything above that there
is no print
but it is appreciated , thank you

Sub PrintList()

' PrintList Macro



Sheets("w002").Select

ZZ = Worksheets("w001").Range("a27").Value ' get value . this is variable



If ZZ => 1 And ZZ <=7 Then ' Only hthis range will
print when value is 1 to 7

ActiveSheet.Range("A2:G36").PrintOut

If ZZ => 8 And ZZ < =14 Then

ActiveSheet.Range("A2:G71").PrintOut

If ZZ => 15 And ZZ < =22 Then

ActiveSheet.Range("a72:G106").PrintOut



End If

End If

End If



End Sub
 
You have got the symbols for greater than and equals the wrong way
round. Also, I would suggest you use ElseIf, as follows:

If ZZ >= 1 And ZZ <=7 Then
ActiveSheet.Range("A2:G36").PrintOut
ElseIf ZZ > 7 And ZZ <=14 Then
ActiveSheet.Range("A2:G71").PrintOut
ElseIf ZZ > 14 And ZZ <=22 Then
ActiveSheet.Range("A72:G106").PrintOut
End If

Not knowing what values ZZ could take, I have changed some of the
comparisons - if ZZ is 7.5, for example, I assume you would want to
print out the middle range. I think your middle range is meant to be
A37:G71. Note that if ZZ is less than 1 or greater than 22, then you
will not get a printout.

Hope this helps.

Pete
 
thank you very much the formula worked spot on
the aim was to dump pages = to members records so I changed the start range
to A2 in all ranges and it dumps the required amount of pages

once again thank you



You have got the symbols for greater than and equals the wrong way
round. Also, I would suggest you use ElseIf, as follows:

If ZZ >= 1 And ZZ <=7 Then
ActiveSheet.Range("A2:G36").PrintOut
ElseIf ZZ > 7 And ZZ <=14 Then
ActiveSheet.Range("A2:G71").PrintOut
ElseIf ZZ > 14 And ZZ <=22 Then
ActiveSheet.Range("A72:G106").PrintOut
End If

Not knowing what values ZZ could take, I have changed some of the
comparisons - if ZZ is 7.5, for example, I assume you would want to
print out the middle range. I think your middle range is meant to be
A37:G71. Note that if ZZ is less than 1 or greater than 22, then you
will not get a printout.

Hope this helps.

Pete
 

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