ListBox Issue

johnsonk

Board Regular
Joined
Feb 4, 2019
Messages
172
Hi, I am using the code below to show the last row of data in a list box from the active sheet but I can only get it to show the first row and I only need to it to show the last row of data can anyone help.


VBA Code:
Private Sub OptionButton1_Click()
If OptionButton1.Value = True Then
Set ws = ActiveSheet
lastrow = ws.Range("N" & Rows.Count).End(xlUp).row + 1
ws.Range("N" & lastrow).Value = ("IN")
End If
 lastrow = Sheet1.Range("A1").CurrentRegion.Rows.Count

Select Case lastrow
Case Is <= 1: Set ws = ActiveSheet.Range("A2:I" & lastrow)
Case Is > 1: Set ws = ActiveSheet.Range("A" & lastrow - 1, "I" & lastrow)
End Select
Me.ListBox1.RowSource = ws.Address
Set ws = Nothing

End Sub



Regards
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
How about
VBA Code:
  Me.ListBox1.List = Range("A" & Rows.Count).End(xlUp).Resize(, 9).Value
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,829
Messages
6,127,130
Members
449,361
Latest member
VBquery757

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