Select ListBox entry & go to that entry in worksheet

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Evening,

I have a userform with a listbox.
I would like to select an entry in the listbox & be taken to that person on the worksheet.
I have on the userform another code which uses the entry i select so i can just select & be taken there, Hence why i need to select the entry then have the code on a command button

Some Info for you.
ListBox is called ListBoxSearch
Worksheet called DATABASE
Column A is where it needs to be selected.


I have the code below which i thought would work but i get a run time error,as shown in screenshot

VBA Code:
Private Sub GoToCustomerButton_Click()
 Dim answer As Integer
 
  Range("A" & ListBoxSearch.List(ListBoxSearch.ListIndex, 1)).Select
  answer = MsgBox("GO TO CUSTOMER IN DATABASE ?", vbYesNo + vbInformation, "OPEN DATABASE MESSAGE")
   If answer = vbYes Then
   Unload FindAndReplaceDatabase
   Database.LoadData Sheets("DATABASE"), Selection.Row

Else
    Unload FindAndReplaceDatabase
End If
End Sub
 

Attachments

  • 6942.jpg
    6942.jpg
    30.6 KB · Views: 7

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
You did not indicate what line gives rise to the error though
 
Upvote 0
ListBoxSearch.List(ListBoxSearch.ListIndex, 1) is likely not a number.

In a recent question you were trying to load the row number into the 4th column of your list box.
List box columns are zero based (0, 1, 2, 3) so to refer to the 4th column it would be
ListBoxSearch.List(ListBoxSearch.ListIndex, 3)
 
Upvote 0
Hi
Does my code look correct other than the error ?
I’m not at pc now so will look tomorrow.
I can populate the listbox no problem.
I see an entry so I click on it & now wish to go to that entry on the worksheet.
The search I had carried out in this case was a number search. The listbox is populated with that number in question. Row. Customers name. Date. Now I just need to go to the row where this data was collected from.

I got / get lost with some codes like the one I have shown above.
I mean what does the A & 1 represent ???
 
Upvote 0
Morning,
Ive changed the 1 to 2 & now the code below does what i require.

Many thanks

Code:
Private Sub GoToCustomerButton_Click()
  Dim answer As Integer
  With ListBoxSearch
  Range("A" & ListBoxSearch.List(ListBoxSearch.ListIndex, 2)).Select
  Unload FindAndReplaceDatabase
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,870
Messages
6,122,021
Members
449,060
Latest member
LinusJE

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