Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8574053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:23:20+00:00 2026-06-11T19:23:20+00:00

i write a code as follow: Call search(xx, yy, APM Output, >> State Scalars,

  • 0

i write a code as follow:

Call search(xx, yy, "APM Output", ">> State Scalars", label1)

label1:
      ...........

this the script of Sub search

Sub search(row As Variant, col As Variant, wkst As String, str As String, label_num As Name)
For row = 1 To 100
  For col = 1 To 100
    strTemp = Worksheets(wkst).Cells(row, col).Value
    If InStr(strTemp, str) <> 0 Then
        GoTo label_num
    End If
  Next
Next
End Sub

i want to call sub search(..) firstly, and then go to label1.
The problem is that is says that “ByRef argument type mismatch” for label_num.What should be the correct type for label_num in Sub search(..,..,..,label_num)?

i add some original script, these are what I want to convert into a sub()

For xx = 1 To 100
    For yy = 1 To 100
        strTemp = Worksheets("APM Output").Cells(xx, yy).Value
        If InStr(strTemp, ">> State Scalars") <> 0 Then
            GoTo label1
        End If
    Next
Next
label1:
    For uu = 1 To 100
        For vv = 1 To 100
            strTemp = Worksheets("APM Output").Cells(uu, vv).Value
            If InStr(strTemp, ">> GPU LPML") <> 0 Then
                GoTo label2
            End If
        Next
    Next
label2:
    For mm = 1 To 100
        For nn = 1 To 100
            strTemp = Worksheets("APM Output").Cells(mm, nn).Value
            If InStr(strTemp, ">> Limits and Equations") <> 0 Then
                GoTo label3
            End If
        Next
    Next
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:23:22+00:00Added an answer on June 11, 2026 at 7:23 pm

    As a good practise, please avoid using label at all cost!

    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

    the following code is how to avoid using label

    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, ">> State Scalars") <> 0 And Not found1 Then
               found1 = True
               xx = i
               yy = j
           End If
    
           If InStr(strTemp, ">> GPU LPML") <> 0 And Not found2 Then
               found2 = True
               uu = i
               vv = j
           End If
           If InStr(strTemp, ">> Limits and Equations") <> 0 And Not found3 Then
               found3 = True
               mm = i
               nn = j
           End If
       Next j
    Next i
    

    to make your function into a sub, simply do

    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 ) <> 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
    

    and call it 3 times,
    for example:

    my_search xx,yy,">>State Scalars", 100, 100, Worksheets("APM Output")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I write code to connect through Windows VPN client? I want this
I occasionally write code something like this: // file1.cpp #define DO_THIS 1 #if DO_THIS
I follow this sample http://trac.osgeo.org/proj/wiki/ProjAPI but if I try to import this code in
Possible Duplicate: excel macro: ByRef argument type mismatch i write a code as follow:
Hello guys in my code i'm getting this stack: Traceback (most recent call last):
I want to create 1MB String for benchmark,so I writed code as follow: public
I'm trying to write code in my controller that when run, will create a
I m trying write code that after reset set up rrpmax as 3000. It
I am trying to write code for getting my cords on the mobile. I
I'm trying to write code that will load an image from a resource, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.