Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default Listbox Select Last Value in range

Is there a line i can ADD to the below code to select the LAST value(not empty) in the Range ?

Private Sub UserForm_Initialize()
Dim myCell As Range
Dim myRng As Range
Set myRng = Worksheets("RTW Plan").Range("N80:N99")
With ListBox1
For Each myCell In myRng.cells
If Trim(myCell.Value) = "" Then
'skip it
Else
.AddItem myCell.Value
End If
Next myCell
End With
End Sub

Corey....


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Listbox Select Last Value in range

As long as non-empty cells are skipped, you can just pick out the last one
added.

Private Sub UserForm_Initialize()
Dim myCell As Range
Dim myRng As Range
Set myRng = Worksheets("RTW Plan").Range("N80:N99")
With ListBox1
For Each myCell In myRng.Cells
If Trim(myCell.Value) = "" Then
'skip it
Else
.AddItem myCell.Value
End If
Next myCell
.ListIndex = .ListCount - 1
End With
End Sub

The count of the items in the list goes from 1 to N.
The first item in the list is 0. So it's indexed from 0 to N-1.



Corey wrote:

Is there a line i can ADD to the below code to select the LAST value(not empty) in the Range ?

Private Sub UserForm_Initialize()
Dim myCell As Range
Dim myRng As Range
Set myRng = Worksheets("RTW Plan").Range("N80:N99")
With ListBox1
For Each myCell In myRng.cells
If Trim(myCell.Value) = "" Then
'skip it
Else
.AddItem myCell.Value
End If
Next myCell
End With
End Sub

Corey....


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 363
Default Listbox Select Last Value in range

Thank you Dave.

"Dave Peterson" wrote in message
...
As long as non-empty cells are skipped, you can just pick out the last one
added.

Private Sub UserForm_Initialize()
Dim myCell As Range
Dim myRng As Range
Set myRng = Worksheets("RTW Plan").Range("N80:N99")
With ListBox1
For Each myCell In myRng.Cells
If Trim(myCell.Value) = "" Then
'skip it
Else
.AddItem myCell.Value
End If
Next myCell
.ListIndex = .ListCount - 1
End With
End Sub

The count of the items in the list goes from 1 to N.
The first item in the list is 0. So it's indexed from 0 to N-1.



Corey wrote:

Is there a line i can ADD to the below code to select the LAST value(not empty) in the Range ?

Private Sub UserForm_Initialize()
Dim myCell As Range
Dim myRng As Range
Set myRng = Worksheets("RTW Plan").Range("N80:N99")
With ListBox1
For Each myCell In myRng.cells
If Trim(myCell.Value) = "" Then
'skip it
Else
.AddItem myCell.Value
End If
Next myCell
End With
End Sub

Corey....


--

Dave Peterson


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Listbox Select Last Value in range

You're welcome.

Corey wrote:

Thank you Dave.

"Dave Peterson" wrote in message
...
As long as non-empty cells are skipped, you can just pick out the last one
added.

Private Sub UserForm_Initialize()
Dim myCell As Range
Dim myRng As Range
Set myRng = Worksheets("RTW Plan").Range("N80:N99")
With ListBox1
For Each myCell In myRng.Cells
If Trim(myCell.Value) = "" Then
'skip it
Else
.AddItem myCell.Value
End If
Next myCell
.ListIndex = .ListCount - 1
End With
End Sub

The count of the items in the list goes from 1 to N.
The first item in the list is 0. So it's indexed from 0 to N-1.

Corey wrote:

Is there a line i can ADD to the below code to select the LAST value(not empty) in the Range ?

Private Sub UserForm_Initialize()
Dim myCell As Range
Dim myRng As Range
Set myRng = Worksheets("RTW Plan").Range("N80:N99")
With ListBox1
For Each myCell In myRng.cells
If Trim(myCell.Value) = "" Then
'skip it
Else
.AddItem myCell.Value
End If
Next myCell
End With
End Sub

Corey....


--

Dave Peterson


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select a ListBox value with code Riddler Excel Programming 0 November 20th 06 04:21 PM
MultiColumn ListBox, linked to a range - select cells Spencer Hutton Excel Programming 1 March 20th 05 12:12 AM
Multi-select listbox help! John[_60_] Excel Programming 3 October 9th 04 01:57 AM
multi select listbox Paul Mueller Excel Programming 2 June 10th 04 09:08 PM
Select from table and listbox PawelR Excel Programming 1 November 7th 03 01:21 PM


All times are GMT +1. The time now is 07:05 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"