Consulting

Results 1 to 8 of 8

Thread: Get row number from a closed workbook

  1. #1
    VBAX Newbie
    Joined
    Jan 2019
    Posts
    4
    Location

    Get row number from a closed workbook

    I am trying to get the row number, where the criteria meets a certain value

    I have been trying with this code:
    Dim wkb As Workbook
    Dim a As Range
        Dim clientwks As Worksheet
        Dim listrange As String
      Dim foundValue As Range
      Dim fundet As Integer
      Dim clientlist As Range
      Dim listen As Range
    
      Set wkb = Workbooks.Open("Q:\KUNDER\PROJEKTER\HPG\HPG_DB.xlsx")
        Set clientwks = wkb.Sheets("Template_0")
        Set clientlist = clientwks.Range("A1")
        listrange = "PRO123456"
        Set listen = Range("A1", Range("A1").End(xlDown))
    For Each a In listen
      Set foundValue = clientlist.Cells.Find(listrange)
      If Not foundValue Is Nothing Then
        a.Offset(0, 0).Value = foundValue.Row
      End If
      Next a

  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    a.Offset(0, 0).

    ???

    Option Explicit
    
    
    Sub test()
        Dim f As String
        
        f = "=Iferror(match(A1,'Q:\KUNDER\PROJEKTER\HPG\[HPG_DB.xlsx]Template_0'!$A:$A,0),A1)"
    
        With Range("A1", Range("A1").End(xlDown)).Offset(, 1)
            .Formula = f
            .Value = .Value
        End With
        
    End Sub

  3. #3
    VBAX Newbie
    Joined
    Jan 2019
    Posts
    4
    Location
    f = "=Iferror(match(A1,'Q:\KUNDER\PROJEKTER\HPG\[HPG_DB.xlsx]Template_0'!$A:$A,0),A1)"

    Where to put my searchstring and how do I get the result
    Last edited by cisterne; 01-17-2019 at 05:16 AM.

  4. #4
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    >Where to put my searchstring and how do I get the result

    column-A :
    searchstring
    column-B :
    result

  5. #5
    VBAX Newbie
    Joined
    Jan 2019
    Posts
    4
    Location
    I think i didnt make myself clear enough

    Get row number from a closed workbook

    I am trying to get the row number, where the criteria meets a certain value


    The search string is "PRO123456" and the column to search is "A1" - when it match i would like it to tell me the rownumber

  6. #6
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Sub test2()
        Dim s As String
        
        s = "PRO123456"
    '   Cells(1).Formula = "=Iferror(match(""" & s & """,'Q:\KUNDER\PROJEKTER\HPG\[HPG_DB.xlsx]Template_0'!$A:$A,0),""not found"")"
    
    End Sub

  7. #7
    VBAX Newbie
    Joined
    Jan 2019
    Posts
    4
    Location
    Apparently i cant explain my self

    search for s
    return the row number where the match is
    set a variable equal to the row number

  8. #8
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Sub test3()
       Dim s As String
        Dim f As String
        Dim n
    
        s = "PRO123456"
        f = "=Iferror(match(""" & s & """,'Q:\KUNDER\PROJEKTER\HPG\[HPG_DB.xlsx]Template_0'!$A:$A,0),""not found"")"
    
        With Cells(Columns.Count)
            .Formula = f
            n = .Value
            .Clear
        End With
        
        MsgBox "row number : " & n
        
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •