Consulting

Results 1 to 2 of 2

Thread: Find column (in Excel address) of matching value in array

  1. #1
    VBAX Newbie
    Joined
    Aug 2011
    Posts
    5
    Location

    Find column (in Excel address) of matching value in array

    I need to find the Column, e.g. "L" (in the Excel address) for the cell in an Array read in from Excel which contains a value matching a specified variable x.



    [vba]

    Public Sub RetAdr()
    Dim VarArray as Variant
    Dim x as integer
    Dim RetAddress as String

    x= 12 ' As an example,... looking for the Column of cell containing the value: 12

    VarArray = Worksheets("Sheet1").Range("A1:CV1") ' values in VarArray are: 1,2,3... 100
    RetColAddress = WorksheetFunction.Address(WorksheetFunction.Match(x,VarArray,0)) ' Need help here!

    MsgBox = RetColAddress ' Should display "L"
    End Sub
    [/vba]

  2. #2
    VBAX Tutor
    Joined
    Nov 2006
    Location
    North East Pennsylvania, USA
    Posts
    203
    Location
    Lagos,


    Try this:


    [VBA]

    Option Explicit
    Public Sub RetAdr()
    Dim VarArray As Variant
    Dim x As Long
    Dim RetColAddress As String
    x = 12
    VarArray = Worksheets("Sheet1").Range("A1:CV1")
    RetColAddress = Replace(Cells(1, Application.Match(x, VarArray, 0)).Address(0, 0), 1, "")
    MsgBox "RetColAddress = " & RetColAddress
    End Sub

    [/VBA]


    Have a great day,
    Stan

Posting Permissions

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