+ Reply to Thread
Results 1 to 26 of 26

VBA explanation

  1. #1
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    167

    VBA explanation

    HI,

    can someone explain me this code?

    Please Login or Register  to view this content.
    Last edited by extremis; 08-09-2013 at 10:42 AM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA explanation

    It finds the first blank cell in column A on a worksheet and pastes values to it.

    What is pasted and what sheet it's pasted will be determined in the preceding lines of code.
    If posting code please use code tags, see here.

  3. #3
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: VBA explanation

    /e My mistake I misread the OP.
    Last edited by Solus Rankin; 08-09-2013 at 10:06 AM.
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  4. #4
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: VBA explanation

    Please Login or Register  to view this content.
    The syntax for Cells() is cells(row number, column) so the above code references Cells(however many rows are in my sheet, column A)
    ".End(xlUp)" tells excel to move from the row number you earlier specified, upward, until it finds a cell with contents. it basically selects the last used cell in the specified column (column A)

    Please Login or Register  to view this content.
    This says "move one row down from Cells(however many rows are in my sheet, column A) and paste only the values from the range that was previously copied."
    Last edited by LaffyAffy13; 08-09-2013 at 10:10 AM.
    ~~LaffyAffy13~~

    If I have helped you solve your problem, please be sure to click at the bottom left of my post.

    Thanks.

  5. #5
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    167

    Re: VBA explanation

    so basicly...if i have a blank space in column A, then copy the value from "where you reference is''

    ???

  6. #6
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: VBA explanation

    so basicly...if i have a blank space in column A, then copy the value from "where you reference is''
    I don't know what that says. Regardless of your blank spaces in column A, the line of code you posted will undoubtedly find the last cell in Column A that has been used, and paste the information directly below it.
    Last edited by LaffyAffy13; 08-09-2013 at 10:16 AM.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA explanation

    Not quite.

    It doesn't find any blank cell in column A.

    The code finds the first blank cell in column A and copies to there.

  8. #8
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: VBA explanation

    Not any blank space, but the bottom row. If you currently use 900 rows it will place it in 901. If you have 9000 rows it will place it in 9001.

    If row 300 is blank but you have data in 301-500 it will place it in row 501.

  9. #9
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: VBA explanation

    Yes, what Solus said.

  10. #10
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    167

    Re: VBA explanation

    Alright, thanks....So it can be useful to fill a space between rows right?
    Like
    11
    Blank
    22

    Right?

  11. #11
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: VBA explanation

    For that it might be easiest to loop through the column to find the first blank row.

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA explanation

    No.

    If you had data like that the code would find the cell under 22, not the blank cell.

    To fill in blanks take a look at SpecialCells(xlCellTypeBlanks).

  13. #13
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: VBA explanation

    It won't be useful for filling in spaces between rows that currently have data.

  14. #14
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: VBA explanation

    Please Login or Register  to view this content.
    Last edited by Solus Rankin; 08-09-2013 at 10:26 AM. Reason: edit code

  15. #15
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    167

    Re: VBA explanation

    Alright...

    but it's only useful to fill thre last cell of a range of data?

  16. #16
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA explanation

    XeRo

    What are you pasting in that code?

    Also where is Row defined?

  17. #17
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA explanation

    extremis

    It's not only used to fill the last cell with data.

    You could be pasting a whole chunk of data.

    For example you might be consolidating data on multiple sheets onto one sheet.

    Using the code you posted you can append the data from each sheet below the data that's already there.

  18. #18
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: VBA explanation

    I'm pasting two white bunnies in a snow storm

  19. #19
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA explanation

    That's what I thought.

  20. #20
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: VBA explanation

    Norie, if you're talking about ".Row", that just refers to the row's number. So he's all good. As for the pasting, maybe its two white bunnies in a snowstorm?

  21. #21
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    167

    Re: VBA explanation

    thanks for your help ...helped a lot

  22. #22
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: VBA explanation

    It would only paste if the clipboard was pre-loaded.

  23. #23
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: VBA explanation

    @ Laffy...

    He was pointing out a typo. It should be rows.count. Rows the collection.

  24. #24
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA explanation

    XeRo

    I know, it pasted an entire Change sub into A2 when I ran it after changing Row to Rows.

  25. #25
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: VBA explanation

    Good thing it wasn't in the ws change event then :D

  26. #26
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: VBA explanation

    Oh, that makes sense. You must have edited it before I saw the problem. Yay for teamwork :D

+ 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] Explanation VBA FOR...NEXT loop
    By burnettec in forum Excel Programming / VBA / Macros
    Replies: 27
    Last Post: 12-31-2012, 12:57 AM
  2. Formula explanation
    By arke in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-28-2012, 06:25 AM
  3. VBA explanation
    By Darel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-01-2011, 02:00 AM
  4. Code explanation
    By bajdr47 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-06-2011, 12:30 PM
  5. Explanation
    By ro55co in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-29-2008, 08:15 AM

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