Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As a good practise, please avoid using label at all cost! </p> <p>I am going to answer you just modifying your code, I guess you want to save the values of xx,yy,uu,vv,mm,nn</p> <p>the following code is how to avoid using label</p> <pre><code>Dim found1 As Boolean Dim found2 As Boolean Dim found3 As Boolean found1 = False found2 = False found3 = False For i = 1 To 100 For j = 1 To 100 strTemp = Worksheets("APM Output").Cells(i, j).Value If InStr(strTemp, "&gt;&gt; State Scalars") &lt;&gt; 0 And Not found1 Then found1 = True xx = i yy = j End If If InStr(strTemp, "&gt;&gt; GPU LPML") &lt;&gt; 0 And Not found2 Then found2 = True uu = i vv = j End If If InStr(strTemp, "&gt;&gt; Limits and Equations") &lt;&gt; 0 And Not found3 Then found3 = True mm = i nn = j End If Next j Next i </code></pre> <p>to make your function into a sub, simply do </p> <pre><code>Sub my_search(ByRef rowNum As Long, ByRef colNum As Long, ByVal searchString As String, ByVal height As Long, ByVal width As Long, ByRef ws As Worksheet) Dim i As Long Dim j As Long Dim found As Boolean found = False Dim strTemp With ws For i = 1 To height For j = 1 To width strTemp = ws.Cells(i, j).Value If InStr(strTemp, searchString ) &lt;&gt; 0 And Not found1 Then found = True rowNum = i 'assigning rowNum colNum = j 'assigning colNum Exit For End If Next j If found Then Exit For End If Next i End With End Sub </code></pre> <p>and call it 3 times, for example:</p> <pre><code>my_search xx,yy,"&gt;&gt;State Scalars", 100, 100, Worksheets("APM Output") </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.
    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