jayjay2022

New Member
Joined
May 28, 2022
Messages
9
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Hi everyone,
I am wanting to set focus on the last entry in my listbox, after I have added to the database.

Currently my listbox only displays when an entry has been made. The listbox shows the complete database which is fine, but I am wanting to set focus on the lastline as this is the current entry.

See screenshopt below

1653940285709.png


This is the code I am using just for the listbox -

ListBox1.ColumnCount = 8
ListBox1.RowSource = "A1: J65356"


Can someone please help me? Thanks in advance.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
You can use the TopIndex property of the ListBox object . . .

VBA Code:
With ListBox1
    .TopIndex = .ListCount - 1
End With

Hope this helps!
 
Upvote 0
You can use the TopIndex property of the ListBox object . . .

VBA Code:
With ListBox1
    .TopIndex = .ListCount - 1
End With

Hope this helps!
Hi Domeric,

I tried the code you provided. The only issue now is that it goes to the bottom of the row, so I need to scroll up.

Thanks for you input - I will see if I can get this working properly.
 
Upvote 0
Sorry, I missed the fact that you're assigning the RowSource property a large static range. Try running the following line of code to update the range after each time an entry is made...

VBA Code:
ListBox1.RowSource = worksheets("Sheet1").range("a1").currentregion.address(external:=true)

Change the sheet name accordingly. Although, if you convert your range into a Table (Ribbon >> Insert >> Tables >> Table), you can use the following instead...

VBA Code:
ListBox1.RowSource = "Table1"

Change the table name accordingly.

Hope this helps!
 
Last edited:
Upvote 0
Solution
Sorry, I missed the fact that you're assigning the RowSource property a large static range. Try running the following line of code to update the range after each time an entry is made...

VBA Code:
ListBox1.RowSource = worksheets("Sheet1").range("a1").currentregion.address(external:=true)

Change the sheet name accordingly. Although, if you convert your range into a Table (Ribbon >> Insert >> Tables >> Table), you can use the following instead...

VBA Code:
ListBox1.RowSource = "Table1"

Change the table name accordingly.

Hope this help!
Thank you for adjustting the code.

I manage to get the code to work with my lisbox, Thanks again.
 
Upvote 0

Forum statistics

Threads
1,215,553
Messages
6,125,483
Members
449,233
Latest member
Deardevil

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