ComboBox starts from last row

ShackerS

New Member
Joined
May 6, 2013
Messages
21
Greetings ,,

with this code, how can I make my combobox1 starts with the last record ??

Code:
Private Sub UserForm_Initialize()Dim cell As RangeWith Worksheets("Sheet1")For Each cell In .Range("C2:C" & .Cells(Rows.Count, 3).End(xlUp).Row)If Not IsEmpty(cell) Then ComboBox1.AddItem cell.ValueNext cellEnd With </pre>[COLOR=#333333]
[/COLOR]
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Code:
Option Explicit
Private Sub UserForm_Initialize()
Dim l As Long
Dim rng As Range
With Worksheets("Sheet1")
    Set rng = .Range("C2:C" & .Cells(Rows.Count, 3).End(xlUp).Row)
    
    For l = rng.Rows.Count To 1 Step -1
    
        If Not IsEmpty(rng.Cells(l, 1)) Then ComboBox1.AddItem rng.Cells(l, 1)
    
    Next l
End With
End Sub

Something like this? (untested)
 
Upvote 0
With this code, how can I make my combobox1 starts with the last record ??
Code:
Private Sub UserForm_Initialize()
  Dim Cell As Range
  With Worksheets("Sheet1")
    For Each Cell In .Range("C2:C" & .Cells(Rows.Count, 3).End(xlUp).Row)
      If Not IsEmpty(Cell) Then ComboBox1.AddItem Cell.Value
    Next Cell
  End With
  [B][COLOR=#a52a2a]ComboBox1.ListIndex = ComboBox1.ListCount - 1[/COLOR][/B]
  ....
  ....
End Sub
Add the line I show in red above.
 
Upvote 0

Forum statistics

Threads
1,216,091
Messages
6,128,779
Members
449,468
Latest member
AGreen17

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