Listbox1 Error

GomaPile

Active Member
Joined
Jul 24, 2006
Messages
334
Office Version
  1. 365
Platform
  1. Windows
Hello to All and happy Independencia (4th) Day to everyone,

Im bored!! Having a play using Listbox's & Textbox's - anyways found this vba code while browsing on YouTube but it won't work. Sadly, there was no support in the comments section neither.

Im in no rush guys.... did checked & double checked the code over and over. No idea why it stopped at this point - Me.ListBox1.List(0, lst - 1) = Sheet2.Cells(1, lst)
And Im guessing there more errors after that one... who knows lol lol

VBA Code:
Private Sub TextBox1_Change()

Dim rng As Range
Dim r As Long
Dim cln, lst As Integer
   
Me.ListBox1.Clear
Set rng = Sheet2.Range("A4").CurrentRegion
Me.ListBox1.AddItem
For lst = 1 To rng.Columns.Count
Me.ListBox1.List(0, lst - 1) = Sheet2.Cells(1, lst) [COLOR=rgb(65, 168, 95)]' <------------- Error stops here[/COLOR]
Next lst
Me.ListBox1.Selected(0) = True
For r = 2 To rng.Rows.Count
If InStr(UCase(Sheet2.Cells(r, "A")) & Sheet2.Cells(r, "B"), UCase(Me.TextBox1)) > 0 _
And Me.TextBox1 <> "" Then
Me.ListBox1.AddItem
For cln = 1 To rng.Columns.Count
Me.ListBox1.List(ListBox1.ListCount - 1, cln - 1) = Sheet2.Cells(r, cln)

Next cln
End If
Next r
 
End Sub


Cheers
GomaPile (Nasa2)
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Let's not look at a script that does not work.
Please tell us what you're wanting the script to achieve.

Be specific with sheet names.
Do nor say sheet2
Say sheet named "Alpha" or "Bravo" or such
 
Upvote 0
Hey mate, sure happy to bin that script!! I thought I could have a crack at fixing it myself. As previously mentioned in my first post above I was bored & having a play.

That said, what Im trying to achieve...
  • Sheet2 contains Table1 with 500 lines of data across 30 columns
  • I have created a Userform1 that allows Users to input raw data into Table1 etc etc
  • Also created another Userform2 to Search matching values using Textbox1 that displays in Listbox1
  • Thinking adding 2 more options too - StartDate & EndDate onto Userform2 - please click YouTube below as my refence what Im trying to achieve.
  • In a prefect world - would like to use a Double Click event method whenever Listbox1 has a specific data it writes back to Useform1 to allow Users to re edit, update or delete any records from Table1.
Regards
GomaPile (Nasa2)
 
Upvote 0
I need to let someone else help you. You never mentioned User forms.
And I surely do not know why you would need 2 User Forms.
And I mentioned using sheet names like "Alpha" or "Bravo" But your still using names like Sheet3 or Sheet4. And I do not care to watch a YouTube Video.

And when you mention Tables, you need to say something like Sheet("Alpha") Table named "Charlie"
I'm sure someone else here on the forum will be able to help you. Take care
 
Upvote 0
Thanks ☺️ for trying. Have a nice weekend. As for me... b'day soon and it's going to be a Fine Wine & Dine Weekend.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

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