kelly mort
Well-known Member
- Joined
- Apr 10, 2017
- Messages
- 2,169
- Office Version
- 2016
- Platform
- Windows
Hello everyone,
I am using thus macro to print . Now I am trying to get the counter use numbers in some cells instead of the continuous loops I have been using. How do I modify this code to get me there?
The numbers are in cells A3:A303. And I want it to print from top to bottom.
I am using thus macro to print . Now I am trying to get the counter use numbers in some cells instead of the continuous loops I have been using. How do I modify this code to get me there?
The numbers are in cells A3:A303. And I want it to print from top to bottom.
Code:
Sub PrintTC()
Dim strMyArray() As String
Dim dblMyNumber As Double
Dim strReponse, strFrom, strTo As String
Dim i As Integer
MyInputBox:
strReponse = InputBox("Enter the ID's to print from and to like so 1-20 for ID's 1 to 20:", "Print ID Range Selection")
If Len(strReponse) = 0 Then
Exit Sub
ElseIf InStr(strReponse, "-") = 0 Then
If MsgBox("A valid entry like 1-20 was not made." & vbNewLine & "Try again?", vbYesNo + vbCritical) = vbYes Then
GoTo MyInputBox
Else
Exit Sub
End If
End If
strMyArray() = Split(strReponse, "-")
For i = 1 To Len(strMyArray(0))
If IsNumeric(Mid(strMyArray(0), i, 1)) = True Then
If strFrom = "" Then
strFrom = Mid(strMyArray(0), i, 1)
Else
strFrom = strFrom & Mid(strMyArray(0), i, 1)
End If
End If
Next i
For i = 1 To Len(strMyArray(1))
If IsNumeric(Mid(strMyArray(1), i, 1)) = True Then
If strTo = "" Then
strTo = Mid(strMyArray(1), i, 1)
Else
strTo = strTo & Mid(strMyArray(1), i, 1)
End If
End If
Next i
If strFrom = "" Or strTo = "" Then
If MsgBox("No numeric entry can be determined from one or both entries made." & vbNewLine & "Try again?", vbYesNo + vbCritical) = vbYes Then
GoTo MyInputBox
Else
Exit Sub
End If
End If
Application.ScreenUpdating = False
For dblMyNumber = Val(strFrom) To Val(strTo)
With Sheet56
.Range("N4").Value = Val(dblMyNumber)
.PrintOut
End With
Next dblMyNumber
Application.ScreenUpdating = True
MsgBox "ID's have now been printed.", vbInformation
End Sub