seelect row using list box

isildad

Active Member
Joined
Sep 22, 2004
Messages
325
this code in my list box selects row2
Need to change the code to select the row corresponding to my selection in the list box.
Code:
Sub ListBox1_Change()
Rows("2:2").Select
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

venkat1926

Well-known Member
Joined
Aug 21, 2005
Messages
4,824
try this
Code:
Private Sub ListBox1_Change()
Rows(ListBox1.Value).Select
End Sub
 

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
Code:
Private Sub ListBox1_Change()
With ListBox1
     If .Value <> "" Then Rows(.Value).Select
End With
End Sub
 

isildad

Active Member
Joined
Sep 22, 2004
Messages
325
Thx to both of you.
should have said that listbox is from Forms & not Control Toolbox
Most important the value is sometimes text sometimes numeral
sorry for this,

BTW both codes OK with listbox from Control toolbox BUT work only with numeral values and not text
Thx

Edit: Prefer Control toolbox list box now ,,, just need help with error if value is text
Code OK with numeric values
 

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
try
Code:
Private Sub ListBox1_Change()
With ListBox1
     If Val(.Value) > 0 Then Rows(.Value).Select
End With
End Sub
 

Forum statistics

Threads
1,181,102
Messages
5,928,069
Members
436,586
Latest member
latintxn

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
Top