+ Reply to Thread
Results 1 to 5 of 5

How to include last row function in an excel formula incorporated into a macro

  1. #1
    Registered User
    Join Date
    09-13-2021
    Location
    India
    MS-Off Ver
    365
    Posts
    36

    How to include last row function in an excel formula incorporated into a macro

    HI everyone,

    I am trying to create a macro, using couple of excel formula and record macro option in excel.


    Column A contains repetitive value (i.e, "apple" mentioned 3 times, "Orange" mentioned 2 times down the row).
    First objective is to find the unique value and copy paste it in column C.
    Formula used in column C: =IFERROR(INDEX($A$2:$A$278, MATCH(0,COUNTIF($C$1:C1, $A$2:$A$278), 0)),"")


    Column B contains respective individual value in regards to column A cell value.
    Using concatenate function I wanted to combine column A and column B data separated by a comma.
    Expected output data (i.e Apple (in column C): ABC, FGH, HJK (in column D).
    Formula used in column D: =CONCATENATEIF($A$2:$A$278, C2, $B$2:$B$278, ",")

    The number of rows in the column A and B is not always 278, is there any way to incorporate last used row# into the formula itself or is there any other option ? Thank you

    Recorded Macro:
    Please Login or Register  to view this content.
    Last edited by Lona; 09-23-2021 at 08:22 AM.

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,622

    Re: How to include last row function in an excel formula incorporated into a macro

    You could use such approach (shown on the example of your first subroutine):

    Please Login or Register  to view this content.
    Best Regards,

    Kaper

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

    Re: How to include last row function in an excel formula incorporated into a macro

    One of my favourites, the Replace method.

    Please Login or Register  to view this content.
    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.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: How to include last row function in an excel formula incorporated into a macro

    I like the approach using Replace. Never seen that done before. That said, I've never liked using .Formula.R1C1 (or AutoFill).

    I'd do it like this:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: How to include last row function in an excel formula incorporated into a macro

    Thanks for the rep.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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. How to include a formula in a vba function ?
    By Johnny3Gloves in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-29-2018, 12:36 PM
  2. open file pdf incorporated in excel by vba code
    By xcv in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-23-2016, 02:27 PM
  3. Incorporated Until empty cell with sum function
    By chaz1010 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-16-2014, 06:11 AM
  4. Replies: 1
    Last Post: 10-09-2013, 11:03 AM
  5. [SOLVED] How to include the function NORMSINV(RAND()) in VBA Macro?
    By n_ant in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-22-2013, 12:33 PM
  6. [SOLVED] Using the Split function with another function incorporated is not working correctly
    By highlystrung in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-06-2013, 03:51 PM
  7. Replies: 0
    Last Post: 11-26-2005, 12:40 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