+ Reply to Thread
Results 1 to 9 of 9

VB Code to find row Number and its corresponding value

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    VB Code to find row Number and its corresponding value

    Hello:

    I need VB Code to find "Total:" in Column H and then get the corresponding value from column I and put in cell S1.
    Also need the row number of text "Total:" and put row number in cell T1

    Please let me know if you have any questions.
    Thanks.

    Riz

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,914

    Re: VB Code to find row Number and its corresponding value

    Try this.

    Sub tst()
        Dim fRow As Long
        With Sheets("Sheet1")
            fRow = Application.Match("Total:", .Columns(8), 0)
            If Not IsError(fRow) Then
                .Cells(1, 19) = .Cells(fRow, 9)
                .Cells(1, 20) = fRow
            End If
        End With
    End Sub
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Forum Contributor
    Join Date
    08-16-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2019
    Posts
    209

    Re: VB Code to find row Number and its corresponding value

    Hi,

    Code to find "Total:" in Column H and then get the corresponding value from column I and put in cell S1
    range("S1").value = range("H" & worksheetfunction.match("Total:","H:H",0))
    Thanks
    Lex

  4. #4
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: VB Code to find row Number and its corresponding value

    Or maybe this...

    Sub FindTotal()
    Dim rngTotal As Range
    Set rngTotal = Range("H:H").Find("Total:", lookat:=xlWhole)
    If Not rngTotal Is Nothing Then
        Range("S1").Value = rngTotal.Offset(0, 1).Value
        Range("T1").Value = rngTotal.Row
    End If
    End Sub
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2406 Win 11 Home 64 Bit
    Posts
    24,035

    Re: VB Code to find row Number and its corresponding value

    and yet another solution. Take your pick.
    Option Explicit
    
    Sub Riz()
        Dim lr As Long, r As Long, start As String, endX As String
        lr = Range("H" & Rows.Count).End(xlUp).Row
        start = "H1"
        endX = "H" & CStr(lr)
        r = lr + 1
        Range("H" & lr + 1).Formula = "=Sum(" & start & ":" & endX & ")"
        Range("S1").Value = Range("H" & lr + 1)
        Range("T1") = r
    End Sub
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  6. #6
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: VB Code to find row Number and its corresponding value

    Hello Guys:

    Thanks a lot for great response and the code i needed.
    I know i will be able to use one of the above code.
    Will let you know if any problem, but i know it will work..
    Riz

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,914

    Re: VB Code to find row Number and its corresponding value

    You're welcome and thanks for rep+.

  8. #8
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: VB Code to find row Number and its corresponding value

    You're welcome Riz! Glad we could help.
    Thanks for the rep.

  9. #9
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2406 Win 11 Home 64 Bit
    Posts
    24,035

    Re: VB Code to find row Number and its corresponding value

    You are welcome. Thanks for the rep

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA Code to find a number in another list
    By Bobbbo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-23-2017, 08:11 AM
  2. [SOLVED] VB Code to Find Row Number
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-26-2015, 11:59 AM
  3. [SOLVED] Using MATCH within VBA to find a row number used elsewhere in code
    By jacob@thepenpoint in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-31-2013, 11:01 AM
  4. [SOLVED] Code to find value and divide by defined number
    By narrowgate88 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-24-2013, 09:29 AM
  5. [SOLVED] vba code to find last row value, add new row and auto number new row
    By kawa13 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-13-2013, 06:16 AM
  6. [SOLVED] Find out the reference number for a column for VBA code
    By Jiptastic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-09-2012, 05:27 PM
  7. Need a VB Code to find the max number in a list
    By adaws in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-07-2012, 10:04 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1