Advice to use the same code but from top of sheet down the page

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
Office Version
  1. 2007
Platform
  1. Windows
I am using this short code which will search from Bottom of sheet to the Top.

What change do i need to make to it so it searches from Top of the sheet & down the page.
Thanks

VBA Code:
Private Sub CommandButton2_Click()
    Dim s$, r As Range, i&, ws As Worksheet
    Me.ListBox1.Clear
    s = Me.TextBox8
    If s = "" Then Exit Sub
    Set ws = Sheets("POSTAGE")
    With Me.ListBox1
        .ColumnCount = 4
        .ColumnWidths = "220;130;160;10"
        For i = ws.Range("B" & Rows.count).End(xlUp).Row To 7 Step -1
            If InStr(1, ws.Cells(i, "B"), s, 1) Then
                .AddItem ws.Cells(i, "B")
                .List(.ListCount - 1, 1) = ws.Cells(i, "d") ' INFO
                .List(.ListCount - 1, 2) = ws.Cells(i, "g").Text ' DATE DELIVERED
                .List(.ListCount - 1, 3) = i
            End If
        Next
    End With
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
@ipbr21054 Try like below.

VBA Code:
Private Sub CommandButton2_Click()
    Dim s$, r As Range, i&, ws As Worksheet
    Me.ListBox1.Clear
    s = Me.TextBox8
    If s = "" Then Exit Sub
    Set ws = Sheets("POSTAGE")
    With Me.ListBox1
        .ColumnCount = 4
        .ColumnWidths = "220;130;160;10"
        For i = 7 To ws.Range("B" & Rows.Count).End(xlUp).Row  '<<<<
            If InStr(1, ws.Cells(i, "B"), s, 1) Then
                .AddItem ws.Cells(i, "B")
                .List(.ListCount - 1, 1) = ws.Cells(i, "d") ' INFO
                .List(.ListCount - 1, 2) = ws.Cells(i, "g").Text ' DATE DELIVERED
                .List(.ListCount - 1, 3) = i
            End If
        Next
    End With
End Sub
HTH
 
Upvote 0
Solution

Forum statistics

Threads
1,224,727
Messages
6,180,586
Members
452,988
Latest member
wcself81

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