Listbox not leaving out first 2 rows

dualhcsniatpac

Board Regular
Joined
Feb 18, 2009
Messages
126
I would like to leave out the header rows. When the form is initialized I cant figure out how to leave out the first 2 rows. I am not the original author of this code so thats why I am having trouble. Any help will do.

Thanks

Code:
Private Sub UserForm_Initialize()
    Dim ColCnt As Integer
    Dim rng As Range
    Dim cw As String
    Dim c As Integer
    fname = "High Volume Scrap " & Format(Date, "yyyy") & ".xls"
    SheetName = Format(Date, "mmmm")
    
    ' Sets the working directory
        ChDir ("C:\Test\")
        On Error Resume Next
        Workbooks.Open Filename:="C:\Test\" & fname
        Sheets(SheetName).Select
        
    ColCnt = ActiveSheet.UsedRange.Columns.Count
    Set rng = ActiveSheet.UsedRange
    With ListBox1
        .ColumnCount = ColCnt
        .RowSource = rng.Address
        cw = ""
        For c = 1 To .ColumnCount
            cw = cw & rng.Columns(c).Width & ";"
        Next c
        .ColumnWidths = cw
        .ListIndex = 0
    End With
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Code:
.RowSource = rng.offset(2,0).Resize(rng.Rows.count -2).Address
should do it.
 
Upvote 0

Forum statistics

Threads
1,203,605
Messages
6,056,258
Members
444,853
Latest member
sam69

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