Help with counter in print macro

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. 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.

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
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top