select and print range of rows

  • I was hoping that someone might know how to add pop up windows in excel via a macro in order to
    - prompt the user to enter number of the first row in the range
    - prompt the user to enter number of the last row in the range
    - prompt the user to enter number of printed copies
    - print previously defined range of rows (or just one) on printer (label printer) in number of copies as defined before


    For example, I am using a workbook to print labels (each row is the label), and when I wish to print from row 5 to row 8, I would like a macro to prompt me to enter number 5 as the first row in the range, and then number 8 as last row in the range, and then specify how many times I want to print out each row (label).
    Thank you very much for your attention to this thread, may be you could help me.

  • Re: select and print range of rows


    Hello 092022,


    Your problem is not too hard... take a look at the help files for the Inputbox function, the PrintArea property, and the Printout method.

    If I've been helpful, let me know. If I haven't, let me know that too. 

  • Re: select and print range of rows


    Quote from dangelor

    Hello 092022,


    Your problem is not too hard... take a look at the help files for the Inputbox function, the PrintArea property, and the Printout method.


    Thanks, dangelor
    I've done this macro, but , after selecting rows, HOW TO PRINT OUT THIS RANGE FROM a TO b??


    Sub test01()
    Dim a As Long, response As Long
    a = Application.InputBox( _
    Prompt:="Enter the first Rownumber", _
    Title:="Select first rownumber:", Type:=1)
    b = Application.InputBox( _
    Prompt:="Enter the last Rownumber", _
    Title:="Select last rownumber:", Type:=1)
    Rows(a).Select
    ' HOW TO PRINT OUT THIS RANGE FROM a TO b??
    End Sub

  • Re: select and print range of rows


    Welcome to the Forum!!!



    This code will do what you asked. I have left the input boxes for the start row and finish row with default values in them, eliminate them if you desire.


    HTH,

  • Re: select and print range of rows


    Thank you, Brandtrock
    Using this code as template (below), I actually want to print each row from "test file.xls" (attached) separately (each one on individual continues label). However, before printing, I have to change printing output for each row: only data from first 5 sells should be printed out, each cell on individual line, like in "excel output file.xls" that I've attached here.
    I provided fonts in cell’s comments. Actually, fonts not so important, I can change fonts later if they do not fit into the label.
    Any suggestions how to improve this macro to achieve individual labels printed as I want in "excel output file.xls"?
    Thank you


    Sub PrintRows()
    Dim Times As String
    Dim StartRow As String
    Dim FinRow As String
    StartRow = InputBox("Enter the row to begin printing at: ", "Starting Row")
    FinRow = InputBox("Enter the row to end printing at: ", "Finishing Row")
    Times = InputBox("Enter the number of copies to print: ", "Copies to Print", 1)
    Rows(StartRow & ":" & FinRow).Select
    Selection.PrintOut Copies:=Times, Collate:=True
    End Sub

  • Re: select and print range of rows


    Try this...

    If I've been helpful, let me know. If I haven't, let me know that too. 

  • Re: select and print range of rows


    Thank you, dangelor, this last post is very close to what I want to achieve.
    I still have to fiddle with correct fonts and printer setup, but at least now (with standard 12 size fonts) it prints out, but does not fit the label.
    The biggest problem I have now that printout is too long (see attachment 123.pdf). Is it possible to decrease space (in macro) between 2 columns in printout? so it can be shorter. Also, is it possible to get rid of top and bottom margins in macro?
    I understand that setting up correct driver settings for printer in Windows more important, but after playing with it still can't achieve right printout. That's why I am asking how to correct these settings in Excel macro.
    Thanks

  • Re: select and print range of rows


    Try this, adjusting the column width as necessary...

    If I've been helpful, let me know. If I haven't, let me know that too. 

  • Re: select and print range of rows


    it's much more adjustable now, with ColumnWidth.
    However, what I found, if A4 sell has got long product description, it does not fit into label (see example.pdf)
    Is there any way to make A4 contents automatically go to the next line, if it's too long (A5 should move one line below also). In this case, if A4 is short, it will take only one line, and if it is longer then print area, it will take 2 lines.
    Thanks

  • Re: select and print range of rows


    Sorry to interfer in your conversation, but by reading this tread, it brought me a question in my mind. Is it possible to implement an menu option to choose the printer in this printing macro? If yes, any ideas how?



    Werner

  • Re: select and print range of rows


    Someone helped me out on my question. Here's the answer :


    Code
    Application.Dialogs(xlDialogPrinterSetup).Show
  • Re: select and print range of rows


    WrapText may work. Try...

    If I've been helpful, let me know. If I haven't, let me know that too. 

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!