Listbox Issue

gmazza76

Well-known Member
Joined
Mar 19, 2011
Messages
771
Office Version
  1. 365
Platform
  1. Windows
Good Afternoon,

I am having an issue loading a userform with a listbox on.

It keeps giving the VB issues as "Run-time error'424': Object Required".

I think the line of code it is saying is the issues is the one below in RED.

Any help would be appreciated as the project is nearly done.

Many Thanks

Rich (BB code):
Private Sub UserForm_Initialize()
 
ActiveSheet.AutoFilterMode = False
 
Workbooks.Open Filename:="C:\Users\MAZZA\Documents\Gavin\Car Park\FYVData.xls" 'Home
'Workbooks.Open Filename:="\\W2K6082\COMMON\SHARED\Gavin Mazza\Car Park\FYVData.xls"
 
   With Stats.Range("B1:I14")
        ListBox1.ColumnCount = .Columns.Count
        ListBox1.List = .Value
    End With
 
Dim Today
 
Today = Format(Now, "dd/mm/yyyy")
Me.TextBox1.Value = Today
Me.TextBox1.Locked = True

End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
If Stats is the name of a worksheet in the workbook being opened you can use this.
Rich (BB code):
Private Sub UserForm_Initialize()
 Dim wbData As Workbook
Dim wsStats As Worksheet
ActiveSheet.AutoFilterMode = False
 
Set wbData = Workbooks.Open (Filename:="C:\Users\MAZZA\Documents\Gavin\Car Park\FYVData.xls") 'Home
'Workbooks.Open Filename:="\\W2K6082\COMMON\SHARED\Gavin Mazza\Car Park\FYVData.xls"
 
Set wsStats = wbData.Worksheets("Stats")

   With wsStats.Range("B1:I14")
        ListBox1.ColumnCount = .Columns.Count
        ListBox1.List = .Value
    End With
 

Me.TextBox1.Value = Format(Now, "dd/mm/yyyy")

Me.TextBox1.Locked = True

End Sub
 
Upvote 0
"Stats" is a sheet in "FYVData.xls" that holds the data that i want to pull into the userform.

What do i need to alter?

Cheers
 
Upvote 0
So Stats is a worksheet in the workbook (FYVData.xls) you are opening and you want to populate the listbox with data from it?

If that's the case you don't need to alter anything at all in the code I posted.
 
Upvote 0
Afternoon,

Thanks for the VB, but it seems to debug still but at

Code:
ListBox1.List = .Value
ListBox1.ColumnCount = .Columns.Count

Cheers
Gavin
 
Upvote 0
Gavin

Please tell us how it 'debugs' and post the exact code that it is causing the problem.
 
Upvote 0
All info as requested

As i step through the code the line it debugs at is as follows

Rich (BB code):
ListBox1.ColumnCount = .Columns.Count
ListBox1.List = .Value

and the error "Run-time error '424': Object required"

The code i am using is as below.
Rich (BB code):
Private Sub UserForm_Initialize()
 
Dim Today
 
Today = Format(Now, "dd/mm/yyyy")
Me.TextBox1.Value = Today
Me.TextBox1.Locked = True
 
Dim wbData As Workbook
Dim wsStats As Worksheet
ActiveSheet.AutoFilterMode = False
 
'Set wbData = Workbooks.Open(Filename:="C:\Users\MAZZA\Documents\Gavin\Car Park\FYVData.xls")  'Home
Set wbData = Workbooks.Open(Filename:="\\W2K6082\COMMON\SHARED\Gavin Mazza\Car Park\FYVData.xls")
 
Set wsStats = wbData.Worksheets("Stats")
   With wsStats.Range("B1:I14")
        ListBox1.ColumnCount = .Columns.Count
        ListBox1.List = .Value
    End With
 
Me.TextBox1.Value = Format(Now, "dd/mm/yyyy")
Me.TextBox1.Locked = True
 
End Sub
 
Upvote 0
Is your listbox called ListBox1?
 
Upvote 0
Sorry, due to the question you sent i have realised i didnt address the listbox properly.

Is there anyway i can alter the width of the columns that appear in the listbox?

Many Thanks
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

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