If / Then with multiple variables

MJA001

New Member
Joined
Dec 28, 2017
Messages
28
I use the code below to match a single value in Cell B1 and populate the corresponding info through out the spreadsheet. Instead of a single value in cell B1 I'd there to be multiple values in cell B1 so I can combine multiple reports together.

Currently the value in Cell B1 is something like: 01, and the report will be everything tagged with 01 through the text matching. I'd like the macro to recognize multiple values in a format like: 01, 02 so the report will include everything tagged with 01 and 02.

How can I modify this to include the If code : If Teri = Sheets("Teri Acuna").Range("B1") to recognize both 01, 02 tags?


Dim Teri As Range

Application.ScreenUpdating = False

For Each Teri In Sheets("Project").Range("C2", Sheets("Project").Range("C" & Rows.Count).End(xlUp))
If Teri = Sheets("Teri Acuna").Range("B1") Then
Sheets("Teri Acuna").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = Teri.Offset(0, -1)
End If
Next Teri

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
It's difficult to suggest a full working solution without seeing your actual file. To try to answer this question:
How can I modify this to include the If code : If Teri = Sheets("Teri Acuna").Range("B1") to recognize both 01, 02 tags?
you would have to split the tags in B1. Assuming that there are only 2 tags and they are separated by a comma and a space, this code with split the values:
Code:
If Teri = Split(Sheets("Teri Acuna").Range("B1"), ", ")(0) Or Teri = Split(Sheets("Teri Acuna").Range("B1"), ", ")(1) Then
Can you post a screen shot of what your data looks like? Section B at this link has instructions on how to post a screen shot: https://www.mrexcel.com/forum/board-announcements/127080-guidelines-forum-use.html Alternately, you could upload a copy of your file to a free site such as www.box.com. or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Include a detailed explanation of what you would like to do referring to specific cells and worksheets. If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0
How about
Code:
Dim Teri As Range
Dim Ary As Variant
Ary = Split(Sheets("Teri Acuna").Range("B1"), ",")
Application.ScreenUpdating = False

For Each Teri In Sheets("Project").Range("C2", Sheets("Project").Range("C" & Rows.Count).End(xlUp))
If UBound(Filter(Ary, Teri.Value, True, vbBinaryCompare)) >= 0 Then
Sheets("Teri Acuna").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = Teri.Offset(0, -1)
End If
Next Teri

Application.ScreenUpdating = True


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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