+ Reply to Thread
Results 1 to 7 of 7

VBA code to store the count of last row with value

  1. #1
    Registered User
    Join Date
    10-15-2023
    Location
    London
    MS-Off Ver
    2013
    Posts
    2

    Angry VBA code to store the count of last row with value

    Hi everyone… so I attempted to create a macro that could automatically VLOOKUP a dozen of columns. I managed to create it just that now I’m having a little problem regarding the parameter of the lookup. So I set it from A2:Z100 now. This way this macro would lookup up to row 100 no matter how many data I inputted (for example, I only input 2 rows of data, but the macro would VLOOKUP until 100 rows with row 3-100 have #N/A)

    It’s not aesthetically pretty so I wanted to make a variable called LastRow that could store the number of the last row filled with a value so that the parameter would be “A2:Z & LastRow” instead of “A2:Z100”. I did try to make it using Row.Count but somehow it ended up looking up until 10000+ rows and that’s even worse…

    Can anyone help me with this? Any help would be appreciated!

    So far I only have this:

    Dim LastRow as Integer
    LastRow = ….

    Thank you so much in advance! Hope you all have a good day!

  2. #2
    Forum Contributor
    Join Date
    07-24-2023
    Location
    Como, Italy
    MS-Off Ver
    MSO 365 - Ver 2208
    Posts
    120

    Re: VBA code to store the count of last row with value

    Hi chuluoyi ,

    try this code and let me know:
    Please Login or Register  to view this content.
    Bye
    Max
    let's compare ideas

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: VBA code to store the count of last row with value


    Hi,

    as a reminder LastRow should not be Integer according of a worksheet total rows and
    such variable is useless, just using a With block on the CurrentRegion for example …

  4. #4
    Registered User
    Join Date
    10-15-2023
    Location
    London
    MS-Off Ver
    2013
    Posts
    2

    Re: VBA code to store the count of last row with value

    Hi everyone!
    Thank you for your responses!

    maxpit, I've tried the code but it doesn't work... somehow it affects my lookup code too. Is there another way?

    Marc L, oh, then what should it be? Is it Long? And what is With block? I'm sorry, my knowledge is limited about this...

    Thank you all! Hope to hear from you soon!

  5. #5
    Forum Contributor
    Join Date
    10-02-2012
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    252

    Re: VBA code to store the count of last row with value

    Maxpits code is correct. Did you adjust the column value inside the Cell() function before using it? And yes, Long would be a better choice.

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: VBA code to store the count of last row with value


    Quote Originally Posted by chuluoyi View Post
    Is it Long?
    Yes ! In case of big data …

  7. #7
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,613

    Re: VBA code to store the count of last row with value

    NO: "A2:Z & LastRow”

    Yes: "A2:Z" & LastRow

    (notice the placement of the quotes)
    Ben Van Johnson

+ 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] Count unique items and store results in an Array
    By plans in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-16-2020, 02:57 PM
  2. VBA code for store inventory transfers
    By halimgunawan in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 07-18-2020, 01:02 PM
  3. [SOLVED] VB Code to adjust Inventory count by transfering from one store to another
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-13-2019, 11:15 PM
  4. [SOLVED] Where to store code?
    By Travman1986 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-18-2017, 07:13 AM
  5. Count the number of Failiures per store per question
    By Paxman in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-18-2013, 07:49 AM
  6. [SOLVED] Excel to store history information and display a count of reschedules
    By CollyMitch in forum Excel General
    Replies: 4
    Last Post: 06-07-2006, 03:50 AM
  7. [SOLVED] Count If-e store names listed.
    By Jim in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-25-2005, 11:05 AM

Tags for this Thread

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