Select Listbox value to be then taken to customer on worksheet

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
Office Version
  1. 2007
Platform
  1. Windows
I have the following code in use but when i click on a value in the Listbox i wish to then have that customer selected on my worksheet.
With regards the number 5 in the line of code shown, please advise how i know what number to use.
Im currently going through numbers one by one so it works as opposed to showing an error.
Reason being is i dont know where the 5 is referenced from on the list / sheet etc

VBA Code:
Private Sub ListBox1_Click()
  [COLOR=rgb(184, 49, 47)]Range("A" & ListBox1.List(ListBox1.ListIndex, 5)).Select[/COLOR]
  Unload RoyalMailClaim
End Sub

Private Sub RunCode_Click()
    Dim fndRng As Range
    Dim firstAddress As String
    
With Me.ListBox1
    .ColumnCount = 7
    .ColumnWidths = "100;100;100;100;100;100;100"
End With

With Sheets("POSTAGE").Range("G:G")
    Set fndRng = .Find(What:="RECEIVED NO DATE", LookIn:=xlValues, LookAt:=xlWhole, _
        SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
    If Not fndRng Is Nothing Then
        firstAddress = fndRng.Address
        Do
            ' check the date
            If fndRng.Offset(, -6).Value > Date - 90 Then
                ' add to listbox
                With Me.ListBox1
                    .AddItem fndRng.Offset(, -5).Value                      'CUSTOMER
                    .List(.ListCount - 1, 1) = fndRng.Offset(, 2).Value    'USERNAME
                    .List(.ListCount - 1, 2) = fndRng.Offset(, -4).Value   'ITEM
                    .List(.ListCount - 1, 3) = fndRng.Offset(, -6).Value    'DATE
                    .List(.ListCount - 1, 4) = fndRng.Offset(, -2).Value    'TRACKING NUMBER
                    .List(.ListCount - 1, 5) = fndRng.Offset(, 5).Value    'CLAIM
                    .List(.ListCount - 1, 6) = fndRng.Value                 'TBA
                End With
            End If
            Set fndRng = .FindNext(fndRng)
        Loop While Not fndRng Is Nothing And fndRng.Address <> firstAddress
    End If
End With
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Ive added this line to the code above as i thought it was the reason but now i see variable not defined

VBA Code:
.List(.ListCount - 1, 7) = f.Row                        'ROW
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,098
Members
453,021
Latest member
Justyna P

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