Return Cell Reference of multiple conditions

Hastings

New Member
Joined
Feb 14, 2024
Messages
10
Office Version
  1. 365
Platform
  1. Windows
I would like to execute a script (macro) that would search a spreadsheet and return the cell reference if:

Cell value = Home or Buy or Rent

So my array results would be for example:
A16
Z22
R100
B210

Would be even better if besides the cell references, I could see the value of the cell also. For example:
A16 Home
Z22 Buy
R100 Rent
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
See if something like this would help.

My original sample data is in A1:J20 and the code below produced the list in columns M:N

Hastings.xlsm
ABCDEFGHIJKLMN
1OtherFlatFlatFlat
2HomeFlatOtherB2Home
3FlatSellBuyHomeJ3Home
4FlatSellSellE11Home
5OtherSellB12Home
6RENTSellC18Home
7OtherE19Home
8BuyE3Buy
9FlatA8Buy
10OtherJ16Buy
11SellHomeRentA19Buy
12HomeOtherOtherC20Buy
13B6RENT
14F11Rent
15FlatSellSellF20rent
16Buy
17SellFlat
18FlatHomeSell
19BuyHomeFlat
20BuyrentSell
Sheet1


VBA Code:
Sub Find_Values()
  Dim Itm As Variant
  Dim FirstAddr As String
  Dim rFound As Range
  Dim nr As Long
  
  Const myVals As String = "Home|Buy|Rent"
  
  nr = 2
  With Range("A1:J20")
    For Each Itm In Split(myVals, "|")
      Set rFound = .Find(What:=Itm, LookAt:=xlWhole, MatchCase:=False)
      If Not rFound Is Nothing Then
        FirstAddr = rFound.Address
        Do
          Range("M" & nr).Resize(, 2).Value = Array(rFound.Address(0, 0), rFound.Value)
          nr = nr + 1
          Set rFound = .Find(What:=Itm, After:=rFound, LookAt:=xlWhole, MatchCase:=False)
        Loop Until rFound.Address = FirstAddr
      End If
    Next Itm
  End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,818
Messages
6,181,152
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