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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:28:22+00:00 2026-06-15T20:28:22+00:00

I wrote a code to search a each of the array variable if presents

  • 0

I wrote a code to search a each of the array variable if presents in each row of a Sheet.Now When the match will be found i need to know what the column number is,where the search string has been found. Any idea how to get that using vb script?

ParentColmnCount=ParentColmnCount-1

IntRow6=2

DataCount=0

Do While objSheet6.Cells(IntRow6,1).Value <> ""

For DataCount=0 to UBound(VMHArray)
    If Not objSheet6.Range(objSheet6.Cells(IntRow6,1),objSheet6.Cells(IntRow6,ParentColmnCount)).Find(VMHArray(DataCount)) Is Nothing Then
MsgBox(objSheet6.Range(objSheet6.Cells(IntRow6,1),objSheet6.Cells(IntRow6,ParentColmnCount)).Find(VMHArray(DataCount)).Columns)

    End If
      Next

IntRow6=IntRow6+1

Loop

Update:

 IntRow6=2
 DataCount=0
 Do While objSheet6.Cells(IntRow6,1).Value <> ""

 For DataCount=0 to UBound(VMHArray)


  Set rSearch = objSheet6.Cells(IntRow6,1).EntireRow
  Set rFound = rSearch.Find(VMHArray(DataCount))

        If Not rFound Is Nothing Then
                 adrFirst = rFound.Address

               Do
                   MsgBox(IntRow6)
                   MsgBox(rFound.Column + 1)
                   MsgBox(adrFirst)
                   rCol=rFound.Column
                   objSheet6.Cells(IntRow6,rCol + 2)= objSheet6.Cells(IntRow6,rCol + 5)
                   Set rFound = rSearch.FindNext(rFound)
               Loop Until rFound.Address <> adrFirst And Not rFound Is Nothing
       End If

 Next

 IntRow6=IntRow6+1
 Loop

But it seems the control falls into the infinite Loop and continuously giving 21 as its first matched column number.Producing the output as below:

    2 33 $AF$2     2 33 $AF$2         2 33 $AF$2  .......

Any idea Why So?

Thanks

  • 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-15T20:28:23+00:00Added an answer on June 15, 2026 at 8:28 pm

    Demo script to show how to use .Find:

      Dim oFS    : Set oFS  = CreateObject("Scripting.FileSystemObject")
      Dim sFSpec : sFSpec   = oFS.BuildPath(oFS.GetAbsolutePathname("..\xls"), "13763603.xls")
      Dim oXls   : Set oXls = CreateObject("Excel.Application")
      Dim oWb    : Set oWb  = oXls.Workbooks.Open(sFSpec)
      Dim oWs    : Set oWs  = oWb.Worksheets(2)
      Dim rSearch, rFound, adrFirst
    
      Set rSearch = oWs.Cells(1, 1).EntireRow
      Set rFound = rSearch.Find("b1")
      WScript.Echo 1, "TypeName(rFound):", TypeName(rFound), rFound.Row, rFound.Column
    
      Set rSearch = oWs.Range(oWs.Cells(1, 1), oWs.Cells(5, 3)) 
      Set rFound = rSearch.Find("nix")
      WScript.Echo 2, "TypeName(rFound):", TypeName(rFound)
    
      Set rFound = rSearch.Find("alpha")
      If Not rFound Is Nothing Then
         adrFirst = rFound.Address
         Do
             WScript.Echo 3, "TypeName(rFound):", TypeName(rFound), rFound.Row, rFound.Column
             Set rFound = rSearch.FindNext(rFound)
         Loop Until rFound.Address = adrFirst
      End If
    
      oWb.Close  
      oXls.Quit
    

    output for this sheet:

    alpha sheet:

    1 TypeName(rFound): Range 1 2
    2 TypeName(rFound): Nothing
    3 TypeName(rFound): Range 1 3
    3 TypeName(rFound): Range 2 1
    3 TypeName(rFound): Range 4 2
    3 TypeName(rFound): Range 5 3
    

    Update:

    As can be seen from the output

    ----------------------
    4 1 TypeName(rFound): Range 1 3
    Wahr     rFound.Address <> adrFirst
    Falsch   rFound Is Nothing
    Wahr     Not rFound Is Nothing
    Wahr     rFound.Address <> adrFirst And Not rFound Is Nothing
    

    of my diagnostic code insert into the above script:

      WScript.Echo "----------------------"
      Dim nCnt : nCnt = 0
      Set rFound = rSearch.Find("alpha")
      If Not rFound Is Nothing Then
         adrFirst = rFound.Address
         Do
             nCnt = nCnt + 1
             If nCnt > 9 Then WScript.Echo "Aborting" : Exit Do : End If
             WScript.Echo 4, nCnt, "TypeName(rFound):", TypeName(rFound), rFound.Row, rFound.Column
             Set rFound = rSearch.FindNext(rFound)
             WScript.Echo CStr(rFound.Address <> adrFirst), vbTab, "rFound.Address <> adrFirst"
             WScript.Echo CStr(rFound Is Nothing), vbTab, "rFound Is Nothing"
             WScript.Echo CStr(Not rFound Is Nothing), vbTab, "Not rFound Is Nothing"
             WScript.Echo CStr(rFound.Address <> adrFirst And Not rFound Is Nothing), vbTab, "rFound.Address <> adrFirst And Not rFound Is Nothing"
             WScript.Echo
         Loop Until rFound.Address <> adrFirst And Not rFound Is Nothing
      End If
    

    it’s not a good idea to replace my carefully crafted simple condition

     Loop Until rFound.Address = adrFirst
    

    with something complicated – not to say: silly – like

    Loop Until rFound.Address <> adrFirst And Not rFound Is Nothing
    

    What on earth made you do that?

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

Sidebar

Related Questions

I wrote a small snippet to search for matched strings in an array, then
i wants just know.... to add buttons in each cell in table row.....programmatically in
I want to write a php code that can search for multiple keywords separated
I wrote code to get name of printer which is installed in my system.but
I wrote code first without using functions to prototype, and of course, it worked
I recently wrote code that didnt work as i would expect, it was: message
i added sharekitkit my project. And wrote code like here : SHKItem *item =
I wrote some code in VHDL that is expected to look at a rotory
I wrote this code for zoom in/out . it works but even with one
I wrote this code for zoom in / out and it suppesed to only

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.