Print defined area through visit no.

minmark

New Member
Joined
Jul 18, 2016
Messages
44
[TABLE="width: 500, align: left"]
<tbody>[TR]
[TD]10131[/TD]
[TD]..other infromation.[/TD]
[TD]...[/TD]
[TD].[/TD]
[TD].[/TD]
[/TR]
[TR]
[TD]10132[/TD]
[TD].other infromation....[/TD]
[TD]..[/TD]
[TD].[/TD]
[TD].[/TD]
[/TR]
[TR]
[TD]10133[/TD]
[TD]other infromation.[/TD]
[TD]..[/TD]
[TD].[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]10134[/TD]
[TD]other infromation.[/TD]
[TD].[/TD]
[TD].[/TD]
[TD].[/TD]
[/TR]
[TR]
[TD]10135[/TD]
[TD]other infromation.[/TD]
[TD]..[/TD]
[TD].[/TD]
[TD].[/TD]
[/TR]
</tbody>[/TABLE]







Dear Gents,

I would like to setup a macro that can let me enter the two visit sequence numbers. i,e. 10131 to 10133
and then print the visitors from 10131 to 10133 and their following column contents.

How do I make this happen?
I've tried the inputbox function , range and xldown, but I got stuck in the codes..

Thanks.
 
Assuming your numbers are in column A and you have a header row you can try something like

Code:
Sub findarea()
    Dim sCell As Long, eCell As Long, LstCol As Long, x As String, y As String
    
    LstCol = Cells.Find(What:="*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column

    x = Application.InputBox("Enter start number")
    y = Application.InputBox("Enter end number")

    With Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
        sCell = .Find(What:=x, After:=Cells(1, 1), SearchOrder:=xlByRows, _
                      SearchDirection:=xlNext, LookIn:=xlValues).Row
        eCell = .Find(What:=y, SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row

        ActiveSheet.PageSetup.PrintArea = Range(Cells(sCell, 1), Cells(eCell, LstCol)).Address
    End With
    ActiveSheet.PrintOut
End Sub
 
Last edited:
Upvote 0
wOOOOOO... It's what I want!!!!:bow::bow::bow:
The whole code written in very organized detail.
use x and y to define the start row and end row, what a magic!
You really save me!!
Thanks!

Assuming your numbers are in column A and you have a header row you can try something like

Code:
Sub findarea()
    Dim sCell As Long, eCell As Long, LstCol As Long, x As String, y As String
    
    LstCol = Cells.Find(What:="*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column

    x = Application.InputBox("Enter start number")
    y = Application.InputBox("Enter end number")

    With Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
        sCell = .Find(What:=x, After:=Cells(1, 1), SearchOrder:=xlByRows, _
                      SearchDirection:=xlNext, LookIn:=xlValues).Row
        eCell = .Find(What:=y, SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row

        ActiveSheet.PageSetup.PrintArea = Range(Cells(sCell, 1), Cells(eCell, LstCol)).Address
    End With
    ActiveSheet.PrintOut
End Sub
 
Upvote 0
You're welcome, thanks for the feedback and welcome to the forum.

Btw, no need to quote the previous posts unless you need to specifically refer to them (and even just quote the relevant parts).
 
Last edited:
Upvote 0

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