Consulting

Results 1 to 4 of 4

Thread: Need to pick up the row and column of a cell?

  1. #1

    Need to pick up the row and column of a cell?

    Hi, can someone please help?

    I want to read all the cells in row 3, and if one of the cells is equal to Assumptions!F8, store the row and column value to TEMPNAME.

    I know that I need to do a For Each loop, but I'm struggling. Can someone please help? Thanks

  2. #2
    Can someone please help? This shouldn't take you pro more than 5 mins. Thanks

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    hi.
    you already know the row number, which is 3.


    [vba]
    Sub Find_Row_Col()

    Dim RowNum As Long, ColNum As Long
    Dim FindStr

    FindStr = Worksheets("Assumptions").Range("F8").Value

    RowNum = Cells.Find(What:=FindStr, LookIn:=xlValues, LookAt:=xlPart).Row
    ColNum = Cells.Find(What:=FindStr, LookIn:=xlValues, LookAt:=xlPart).Column

    End Sub
    [/vba]
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  4. #4
    VBAX Mentor Teeroy's Avatar
    Joined
    Apr 2012
    Location
    Sydney, Australia
    Posts
    414
    Location
    Quote Originally Posted by mancubus
    hi.
    you already know the row number, which is 3.
    @mancubus, Priceless

    @doctortt there's another couple of techniques in the code below that might help you. It restricts the search to Row 3 and finds the first match.
    You didn't mention what "TEMPNAME" was so I used an example to write it to a named range on a worksheet sheet.
    [vba]Sub Find_Col()
    Dim rMatch As Range, ColNum As Long
    Set rMatch = Rows(3).Find(What:=[Assumptions!F8], LookIn:=xlValues, LookAt:=xlPart, After:=Cells(3, Columns.Count))
    If Not rMatch Is Nothing Then
    ColNum = rMatch.Column
    Range("TEMPNAME").Value = "3," & ColNum
    End If
    End Sub[/vba]
    _________________________________________________________________________
    "In theory there is no difference between theory and practice. In practice there is." - Chuck Reid

    Any day you learn something new is a day not wasted.

Posting Permissions

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