Link to home
Start Free TrialLog in
Avatar of Bob Hoover
Bob Hoover

asked on

MS Excel VBA Question

Hello

I have a worksheet with 4 columns

DateofBusiness   UnitID   CampaignID    Participate

Where Dateofbusiness is each day of year
And CampaignID is a unique number that will be 1 to 100. Each "campaign" will have each day of year, so sheet will have each day of year listed anywhere from 1 to 100 times in column A.
And Participate will be a 1 or blank - this will be the cell I am attempting to select.

To get to the correct "Participant" cell, I need to search through the "CampaignID" column and find the defined one, and then search the Dateofbusiness to find the defined one. I have been able to do this using one of the fields but am looking for a way to do the lookup and select the correct cell using both parameters.

I have been able to use this shared code to find the cell, but again it is only searching with one parameter

thank you for any recommendations

If Trim(FindString) <> "" Then
        With Sheets("TEST001").Range("A:A")
            Set rng = .Find(What:=FindString, _
                            After:=.Cells(.Cells.Count), _
                            LookIn:=xlValues, _
                            LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlNext, _
                            MatchCase:=False)
           If Not rng Is Nothing Then
                Application.Goto rng, True
                rng.Offset(0, icid).Select
                ActiveCell.Value = 1
            For x = 1 To iSpan
                ActiveCell.Offset(1, 0).Select
                ActiveCell.Value = 1
            Next x
            Else
                MsgBox "Nothing found"
            End If
        End With
Avatar of Norie
Norie

Bob

Which column are you searching first?

In the code it looks like column A and from the way your headings are it would appear that's the DateofBusiness  column, is that correct?

PS If you are trying to search multiple columns you might want to consider concatenation.
Welcome to Experts-Exchange Bob. Can you supply a sample workbook? You do that by clicking the 'Attach File' link at the bottom of a post and the clicking the 'Upload' button.
Avatar of Bob Hoover

ASKER

Norie -
I believe I would need to search Col "C" first to determine campaign, then Col "A" to get date

Martin -
Have uploaded example
Test.xlsm
it is only searching with one parameter
Please describe what you would like to be able to do. In other words I know that it is currently searching using Worksheets("Campaign Master").Range("G2"), but what else do you want to search by?
I also see that the code uses the values in B2 and J2. Are they the other fields that you want to search by?
The other column is Worksheets ("Campaign Master").Range("A2").

Process would be on TEST001 sheet to search for Worksheets ("Campaign Master").Range("A2"), and then Worksheets("Campaign Master").Range("G2").  In this case the selected cell I am trying to get to would be Worksheets ("TEST001").Range("D8").

Another example would be if Campaign 2, Worksheets ("Campaign Master").Range("A3"), and then Worksheets("Campaign Master").Range("G3") then selected cell expectation would be Worksheets ("TEST001").Range("D407") (this would be Campaign (CID) 2 with start date of 12/12/2017
B2 and J2 are not used for the search
So are you saying that there are only the two possible searches that you describe and that you want a way to tell the code to do one or the other?
No - what I am saying is:

Worksheets("Campaign Master").Range("A2") value (in this example 1), search for this value on sheet "TEST001" in Col "C". This is the first part of the search.....

Then
Worksheets ("Campaign Master").Range("G2") value (in this example 12/7/2017), search for this value on sheet "TEST001" in Col "A" . This is the second part of the search. if successful this will  result in cell "A8". (I mentioned "D8" earlier as it is my ultimate end place, but I will use OFFSET to get to it once I can get to "A8")
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Martin - thank you very much, works exactly as needed. I appreciate your patience and assistance
You’re welcome and I’m glad I was able to help.

If you expand the “Full Biography” section of my profile you’ll find links to some articles I’ve written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange Most Valuable Expert (MVE) 2015, 2017
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2017
              Experts Exchange Top Expert VBA (current)