+ Reply to Thread
Results 1 to 9 of 9

Determining the number of rows populated and using that in VBA

  1. #1
    Registered User
    Join Date
    06-07-2017
    Location
    Nottingham, UK
    MS-Off Ver
    2013
    Posts
    15

    Determining the number of rows populated and using that in VBA

    Hi All, As my name suggests I am VERY new to this and finding my way through the world of VBA slowly and cautiously and could do with some help

    I have a spreadsheet where the data in columns A-D are pasted in by the user, and some validation rules are then applied for the user to fix the data. After this they press a button to create a csv, but as each time they paste data in it could be a different number of rows I am using some code I found to ask the user to enter the range they want to export which is a little clumsy.

    What I would like to happen is when the button is pressed, it works out how many rows there are and then this range is exported into the csv.

    I have the saving of the csv file code all sorted (if a little clumsy), but I cant work out how to get the number of rows the user has entered and then add this into the csv creation mode.

    I have looked at usedrange, but because I have formulas in cells to the right, this doesn't work
    I tried a count if to esablish the number of rows (which does work) but I can;t then work out how to get this into the csv file generation code.
    I had a quick look at current region, but can't figure out how how to position it with the other code (or if it will even work).

    Any ideas would be greatly appreciated, the code I have got to so far is below (please don;t laugh too loudly)

    Please Login or Register  to view this content.
    Last edited by jeffreybrown; 06-08-2017 at 05:18 PM. Reason: Please use code tags!

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Determining the number of rows populated and using that in VBA

    Hi,

    Dim another variable to calculate the number of rows. e.g.
    Please Login or Register  to view this content.
    Then use that to set the range to export. i.e.

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Determining the number of rows populated and using that in VBA

    Determining the last row will depend on your data structure

    as you have found out in your investigative work
    there are nuances to determine which is best suited to you

    here is some already made reading for you
    https://stackoverflow.com/questions/...ed-cell-in-vba
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,255

    Re: Determining the number of rows populated and using that in VBA

    How about this ?
    If you want more columns to be copied change the D into the columnletter you desire.

    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.

  5. #5
    Registered User
    Join Date
    06-07-2017
    Location
    Nottingham, UK
    MS-Off Ver
    2013
    Posts
    15

    Re: Determining the number of rows populated and using that in VBA

    Thanks Richard, i wasn't sure how to do those, appreciated.

  6. #6
    Registered User
    Join Date
    06-07-2017
    Location
    Nottingham, UK
    MS-Off Ver
    2013
    Posts
    15

    Re: Determining the number of rows populated and using that in VBA

    Thanks Hum, I'll have a read through as I need to get my knowledge up on these
    EA

  7. #7
    Registered User
    Join Date
    06-07-2017
    Location
    Nottingham, UK
    MS-Off Ver
    2013
    Posts
    15

    Re: Determining the number of rows populated and using that in VBA

    Perfect bakerman... ran and worked first time... nice line of to combine both elements.
    Thank you, have a great Friday everyone

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,255

    Re: Determining the number of rows populated and using that in VBA

    You're welcome and thanks for rep+.

  9. #9
    Registered User
    Join Date
    06-07-2017
    Location
    Nottingham, UK
    MS-Off Ver
    2013
    Posts
    15

    Re: Determining the number of rows populated and using that in VBA

    Perfect bakerman... ran and worked first time... nice line of to combine both elements.
    Thank you, have a great Friday everyone

+ 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] Drop Down Box Shows Both Number and Name-Just want cell populated with Number
    By BDBJ1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-20-2016, 11:15 AM
  2. [SOLVED] Trying to write a Loop to perform calculations within blank rows between populated rows
    By ObliviousAmI in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 01-15-2014, 06:35 PM
  3. Replies: 1
    Last Post: 01-21-2013, 01:57 AM
  4. Replies: 6
    Last Post: 10-04-2012, 11:12 AM
  5. Replies: 2
    Last Post: 06-15-2011, 04:33 PM
  6. [SOLVED] Determining the highest number in a row
    By Jaydubs in forum Excel General
    Replies: 1
    Last Post: 12-07-2005, 11:10 AM
  7. [SOLVED] need help determining a row number
    By Gary Keramidas in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-12-2005, 11:54 PM

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