+ Reply to Thread
Results 1 to 5 of 5

Macro to select the last specific value in a column

Hybrid View

jwpfeiffer Macro to select the last... 09-04-2013, 11:54 AM
GC Excel Re: Macro to select the last... 09-04-2013, 12:07 PM
jwpfeiffer Re: Macro to select the last... 09-04-2013, 12:34 PM
MarvinP Re: Macro to select the last... 09-04-2013, 12:19 PM
GC Excel Re: Macro to select the last... 09-04-2013, 01:24 PM
  1. #1
    Registered User
    Join Date
    12-13-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    2

    Macro to select the last specific value in a column

    I've developed an action tracker where the status of each item is calculated as "R" for items past their due date, "A" for those still within date and "" if completed. This column is sorted Z to A on workbook open so that "R" items appear at the top, followed by "A" items, and "" items last.

    To simplify the process of adding a new action to the list I've created an macro assigned button, but I need to be able to find the last "A" value in column J, so that a new action row can be inserted underneath. I'm currently locating the last value with a cell formula, to which my macro refers, but due to the complexity of the workbook, this calculation takes time and the macro runs slowly.

    Could someone help me with the macro code to find the last "A" value in a sorted column and to insert a row underneath?

    Thanks,
    Justin

  2. #2
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: Macro to select the last specific value in a column

    Hi and welcome to the forum,

    Try this one line of code :
       Columns(1).Find(what:="A", SearchDirection:=xlPrevious).Offset(1, 0).EntireRow.Insert
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  3. #3
    Registered User
    Join Date
    12-13-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Macro to select the last specific value in a column

    Hi - thanks for your response. The code you sent is inserting a row after the last cell in the column containing my formula below, which calculates as a "" value, rather than "A":

    =IF(OR(AND(I4>=TODAY(),K4=""),I4=""),"A",IF(ISNUMBER(K4),"","R"

    Is the code finding the "A" in the formula rather than a calculated value?

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,369

    Re: Macro to select the last specific value in a column

    Hi Justin and welcome to the forum,

    I like to know exactly what is happening so I write code I can read. Here is a UDF (User Defined Function) to return the Row number of the Last R in Column J. See if this code helps you learn VBA.
    Function LastRinJ()
        Dim LastRow As Double
        Dim RowCtr As Double
        LastRow = Cells(Rows.Count, "J").End(xlUp).Row
        
        For RowCtr = LastRow To 1 Step -1
            If Cells(RowCtr, "J") = "R" Then
                LastRinJ = RowCtr
                GoTo Found
            End If
        Next RowCtr
    Found:
        If RowCtr = 0 Then
            MsgBox "You don't have an R in J"
        End If
    End Function
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: Macro to select the last specific value in a column

    Try this instead. The code I provided was for values in column A

    Sub test()
       Dim c As Range
       Set c = Columns(10).Find(what:="A", SearchDirection:=xlPrevious)
       If Not c Is Nothing Then c.Offset(1, 0).EntireRow.Insert
    End Sub
    If it doesn't work, please post sample workbook.

+ 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] Using a macro to select rows with a specific word in a column
    By ahilty in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 07-15-2013, 04:20 PM
  2. Macro to select a specific column of filtered data in a table
    By mgrothendick in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-20-2012, 06:01 PM
  3. Replies: 1
    Last Post: 07-04-2006, 07:00 PM
  4. How to select a specific column with Excel VBA
    By Dennis in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-28-2006, 09:45 AM
  5. Setup a macro to select a specific column within the same row
    By IndioP in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-07-2005, 01:06 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