View Single Post
  #24   Report Post  
Posted to microsoft.public.excel.programming
prkhan56 prkhan56 is offline
external usenet poster
 
Posts: 40
Default Help with Mr. Peterson's Code.. Print serially from a Sheet

Hi Dave,

It shows me two Input Boxes and then gives the following error:
Run-time error '91' Object variable or With block variable not set

This is the complete code now:

Option Explicit
Sub testme()
Dim myRng As Range
Dim myCell As Range
Dim wks As Worksheet
Dim StartVal As Long
Dim EndVal As Long
Dim TempVal As Long
Dim iCtr As Long
StartVal = CLng(Application.InputBox(Prompt:="Start with", _
Default:=1, Type:=1))
If StartVal = 0 Then
Exit Sub
End If
EndVal = CLng(Application.InputBox(Prompt:="End with", _
Default:=StartVal + 1, Type:=1))
If EndVal = 0 Then
Exit Sub
End If
If EndVal < StartVal Then
TempVal = StartVal
StartVal = EndVal
EndVal = TempVal
End If

Set wks = ActiveSheet
Select Case LCase(wks.Name)
Case Is = "pc"
Set myRng = Worksheets("pc details").Range("printarea")
Case Is = "printer"
Set myRng = Worksheets("printer details").Range("printarea")
Case Is = "monitor"
Set myRng = Worksheets("monitor details").Range("printarea")
End Select

'xxx???yyyyy
For Each myCell In myRng.Cells
If IsNumeric(Mid(myCell.Value, 4, 3)) Then
If StartVal <= Val(Mid(myCell.Value, 4, 3)) _
And EndVal = Val(Mid(myCell.Value, 4, 3)) Then
wks.Range("ID").Value = myCell.Value
Application.Calculate 'just in case
wks.Range("printarea").PrintOut preview:=True
End If
End If
Next myCell
End Sub

Rashid Khan