Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A very easy way is to declare the range that you want to search in and the value that you want to find. </p> <pre><code>Sub findValue() Dim xlRange As Range Dim xlCell As Range Dim xlSheet As Worksheet Dim valueToFind valueToFind = "MyValue" Set xlSheet = ActiveWorkbook.Worksheets("Sheet2") Set xlRange = xlSheet.Range("B1:B10") For Each xlCell In xlRange If xlCell.Value = valueToFind Then 'Do Something End If Next xlCell End Sub </code></pre> <p>I'm assuming that your range of ("A5:B5") is a merged cell because you indicated that it contained a single value. Merged cells can just be referenced by the "top left" cell within the merge (or at least that's how I think of it). So your merged range of ("A5:B5") can be referred to as just ("A5"). Anyway, here is a modified version of the method above that is more suited for your needs.</p> <pre><code>Sub findValue(ByVal valueToFind As String) Dim xlRange As Range Dim xlCell As Range Dim xlFormSheet As Worksheet Dim xlSamplesSheet As Worksheet Dim iLastRow As Integer Dim iRow As Integer Dim bFound As Boolean bFound = False Set xlFormSheet = ActiveWorkbook.Worksheets("FeedSampleForm") Set xlSamplesSheet = ActiveWorkbook.Worksheets("FeedSamples") iLastRow = xlSamplesSheet.Range("B1").End(xlDown).Row Set xlRange = xlsamplesheet.Range("B1:B" &amp; iLastRow) For Each xlCell In xlRange If xlCell.value = valueToFind Then bFound = True '&lt;-- The value was found iRow = xlCell.Row '&lt;-- Here is the row that the value was found on End If If bFound Then Exit For '&lt;-- Optional: Exit the for loop once the value is found the first time Next xlCell End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload