Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Looping problem........

Hi

I would like to have a loop in the code below so that it only goes to Print
Preview/Print when A1,A2 & A3 don't equal "ERR". ( This is only an example
the actual range would be "A1:A10").
I would still like the messages to display so the user knows what they need
to look at.

I'm not sure whether or not it is For/Next or Do Until or both. I'd be
grateful for your help.

Regards

Steve

Sub PRINTDoc()


Dim Name As String
Name = Range("b1").Value ' displays username

Application.ScreenUpdating = False


If Range("a1").Value = "ERR" Then MsgBox (Name & ", Please check Qty.")
If Range("a2").Value = "ERR" Then MsgBox (Name & ", Please check Account
No.")
If Range("a3").Value = "ERR" Then MsgBox (Name & ", Please check
Value.")



ActiveSheet.PageSetup.PrintArea = "$A$59:$J$116"
' ActiveWindow.SelectedSheets.PrintOut Copies:=1
ActiveWindow.SelectedSheets.PrintPreview

End Sub



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Looping problem........

Personally, I'd use another column (new column B??) and put all the error
messages in that column. Format the error messages so that they're big bright
bold red:

=if(a1<"err","","Please check qty!")

Then you could just look for ERR in your code:

if application.countif(activesheet.range("a1:A10"),"e rr")0 then
msgbox "Please fix the errors!
else
'do the printpreview.
end if

But if you want code, maybe something like:

Option Explicit
Sub PRINTDoc()

Dim myName As String
Dim RngToCheck As Range
Dim myCell As Range
Dim myMsg As String
Dim iCtr As Long
Dim myWarnings As Variant
Dim HowMany As Long

myWarnings = Array("Qty", _
"Account", _
"Value")

HowMany = UBound(myWarnings) - LBound(myWarnings) + 1

With ActiveSheet
myName = .Range("b1").Value ' displays username
Set RngToCheck = .Range("a1").Resize(HowMany, 1)

iCtr = LBound(myWarnings)
For Each myCell In RngToCheck.Cells
If UCase(myCell.Value) = "ERR" Then
myMsg = myMsg & vbLf & myWarnings(iCtr)
End If
iCtr = iCtr + 1
Next myCell

If myMsg < "" Then
myMsg = myName & ", Please check: " & vbLf & myMsg
MsgBox myMsg
Else
.PageSetup.PrintArea = "$A$59:$J$116"
.PrintPreview
End If
End With

End Sub

Steve Jones wrote:

Hi

I would like to have a loop in the code below so that it only goes to Print
Preview/Print when A1,A2 & A3 don't equal "ERR". ( This is only an example
the actual range would be "A1:A10").
I would still like the messages to display so the user knows what they need
to look at.

I'm not sure whether or not it is For/Next or Do Until or both. I'd be
grateful for your help.

Regards

Steve

Sub PRINTDoc()

Dim Name As String
Name = Range("b1").Value ' displays username

Application.ScreenUpdating = False

If Range("a1").Value = "ERR" Then MsgBox (Name & ", Please check Qty.")
If Range("a2").Value = "ERR" Then MsgBox (Name & ", Please check Account
No.")
If Range("a3").Value = "ERR" Then MsgBox (Name & ", Please check
Value.")

ActiveSheet.PageSetup.PrintArea = "$A$59:$J$116"
' ActiveWindow.SelectedSheets.PrintOut Copies:=1
ActiveWindow.SelectedSheets.PrintPreview

End Sub


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping Problem Paul Black Excel Programming 3 September 17th 05 09:59 AM
Looping problem Sleeping Bear Excel Programming 2 July 7th 05 07:41 PM
Looping Problem . . .Argh! ed Excel Programming 6 December 17th 04 04:18 PM
If Then Else looping problem Kieran1028[_12_] Excel Programming 1 November 11th 04 06:27 PM
Looping Problem Todd Huttenstine[_3_] Excel Programming 5 January 25th 04 12:51 AM


All times are GMT +1. The time now is 03:57 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"