VBA conditional searching for entire cell contents

Time2Learn

New Member
Joined
Apr 22, 2021
Messages
11
Office Version
  1. 365
Platform
  1. Windows
I am trying to write a VBA module to help me identify the source of an excel file that I am given based on known cell values in the header. For example if ""Service Waiver Acknowledged"" exists in any position of the range A1:Z5 then I know this file came from Software1 whereas if ""AnnivDay"" exists in any position of the range A1:Z5 then I know this file came from Software2. I know this because those are unique cell values that do not exist from any other software source in my sample. I was originally doing this:


VBA Code:
Range("A1").Select
ActiveCell.FormulaR1C1 = _
        "=IF(AND(RC[1]=""Last name"",RC[2]=""First name"",RC[12]=""Last Seen"",RC[14]=""""),""Software1 List"","""")"
    Range("A2").Select

the problem with this is someone may have done formatting and moved these columns around or removed one, which would make this fail and not show any result.
Next I tried something like this:

VBA Code:
Dim rng As Range

Set rng = ActiveSheet.Range("A1:Z5")

For Each cell In rng.Cells
   
    If InStr(1, cell, "Last Seen") > 0 Then
        MsgBox ("Software1")
   ElseIf InStr(1, cell, "Last Seen Date") > 0 Then
        MsgBox ("Software2")

The issue here is that Software2 uses ""Last Seen Date"" so this code will not accurately identify ""Last Seen Date"" as Software2.

I've been having trouble finding a good solution for this as I am relatively new to VBA and my googling hasn't provided a good solution.

This is what I'm looking for and I'm sure I'm just not using correct phrasing
If an entire cell contents ""LastSeen"" appears in A1:Z5, then MsgBox ("Software1")
then I can continue that logic with the ElseIf statements for my list of unique identifiers.

Thank you for any suggestions, including how to better post here as this is my first time posting, long time lurker.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
'Settings' worksheet : in column A the key words to identify a software and in column B the software names accordingly …​
This worksheet must be 'sorted' from the most common key words to the less common and special cases before usual cases.​
If the key 'Last Seen Date' identifies a different software than 'Last Seen' so it must be in the list before 'Last Seen'.​
If a software can be identified by 'Last Seen' like by 'Last Seen Date' so the list can contain a single key as 'Last Seen*'.​
Using this worksheet avoids to maintain the code …​
 
Upvote 0
'Settings' worksheet : in column A the key words to identify a software and in column B the software names accordingly …​
This worksheet must be 'sorted' from the most common key words to the less common and special cases before usual cases.​
If the key 'Last Seen Date' identifies a different software than 'Last Seen' so it must be in the list before 'Last Seen'.​
If a software can be identified by 'Last Seen' like by 'Last Seen Date' so the list can contain a single key as 'Last Seen*'.​
Using this worksheet avoids to maintain the code …​
Thank you for giving me another possibility to look into
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

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