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 8577209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:06:31+00:00 2026-06-11T20:06:31+00:00

Possible Duplicate: excel macro: ByRef argument type mismatch i write a code as follow:

  • 0

Possible Duplicate:
excel macro: ByRef argument type mismatch

i write a code as follow:

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

I want to summarize them into a new sub(…) to call, but it has mistake after I test it.

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 

How to modify it? I really need some suggestion.thx

  • 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-11T20:06:32+00:00Added an answer on June 11, 2026 at 8:06 pm

    it’s a good programming practice to split recurrent parts of a sub in a separate function

    I would personally go into the following route:

    Sub Subroutine()
        set tCell = UDF_FindValue("APM Output",">> State Scalars")
        set tCell = UDF_FindValue("APM Output",">> GPU LPML")
        set tCell = UDF_FindValue("APM Output",">> Limits and Equations")
    End Sub
    
    Function UDF_FindValue(WS_Name as String, SearchString as String) as Range
        Set RefWS = WorkSheets(WS_Name)
        for each sCell in intersect(RefWS.Rows("1:100"),RefWS.Columns("1:100"))
            if sCell.value = SearchString then
                Set UDF_FindValue = sCell
                End function
            end if
        next sCell
    End Function
    

    if you make your function general enough, you can also re-use it later…

    it will also enable you to modify your code easily, if, by example, you find out that the find function already does what you want…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: python: creating excel workbook and dumping csv files as worksheets How would
Possible Duplicate: Excel macro to match and lineup rows I have an Excel workbook
Possible Duplicate: Excel Formula Meaning of $ I'm new to the excel macro development,
Possible Duplicate: Excel VBA Double Addition Error I have a very simple VBA macro
Possible Duplicate: Create Excel file in Java How to save output in excel format
Possible Duplicate: Generating an Excel file in ASP.NET Here's my question: How do you
Possible Duplicate: correlation matrix in r I have an excel sheet which has 700
Possible Duplicate: How to properly clean up Excel interop objects in C# I have
Possible Duplicate: In need of JavaScript Solution for Exporting table to Excel which works
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web

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.