Using listbox to reference selection

Noz2k

Well-known Member
Joined
Mar 15, 2011
Messages
693
So basically I have some code which looks up an inputted date, and then if found, uses this reference point to get other values in the same row and then populates another sheet with this data.

It loops through this until no new instances of the date value are found.

This is the code

Rich (BB code):
Dim rng         As Range, _
    rng1        As String, _
    WeekStart   As Date, _
    ws1         As Worksheet, _
    ws2         As Worksheet, _
    findoffset  As Long, _
    lngLastRow  As Long, _
    DT          As Date
 
DT = CDate(txtSetDate.Value)
lngLastRow = Sheets("Sheet1").Cells(Rows.Count, "BS").End(xlUp).Row
Set ws1 = Sheets("Sheet1")
Set ws2 = Sheets("Weekly")
WeekStart = DT - (Weekday(DT, 3))
MsgBox WeekStart
ws1.Unprotect "Password"
findoffset = 0
With ws1.Range("BS3:BS" & lngLastRow)
    Set rng = .Find(WeekStart, LookIn:=xlValues)
    If Not rng Is Nothing Then
        rng1 = rng.Address
 
        Do
            'PerformActions'
 findoffset = findoffset + 1
            Set rng = .FindNext(rng)
        Loop While Not rng Is Nothing And rng.Address <> rng1
    End If
End With

I can place an if statement around the 'perform actions' part of the code, which say only do if rng.offset(,-19) = "A" for instance (based on an input)

However I have a listbox which specifies the value "A" and this may be more than 1 selection. So I have no idea how to reference the value of the selections, and say if rng.offset(,-19) = "A" or "B" or "C" for instance.

Have been stuck on this for a while, and can't get it to go, so any help would be really appreciated.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
As a little more info. I tried getting around the problem by adding this to the code

Code:
Dim X As Long
Dim N As String
Dim G As String
N = ""
    For X = 0 To lstSetSite.ListCount - 1
    If lstSetSite.Selected(X) = True Then
    N = N & Chr(34) & lstSetSite.List(X) & Chr(34) & " or rng.Offset(,-19) = "
    End If
    Next X
G = Left(N, (Len(N) - 3))

and then putting If rng.offset(,-19) = G around the 'perform action' part

but that didn't seem to work
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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