+ Reply to Thread
Results 1 to 10 of 10

VBA issues to copy one cell, then offset, then continue

  1. #1
    Forum Contributor
    Join Date
    05-23-2007
    Posts
    126

    VBA issues to copy one cell, then offset, then continue

    I'm attaching an example file.
    We'll record sales in order, with seller name.
    I've tried (unsuccessfully) to create VBA to summarize (cells H2:M12). Goal is to find (for example) "Seller 1" in column B, and each time it finds "Seller 1", offset to column A, copy that cell, and paste to the right of the seller's name in column H. Then keep looking down B, and keep pasting to the right of H...
    I know what's going wrong (I keep resetting to the first reference), but I don't know how to fix...

    Any help is appreciated. The code is in the file, but also posted here.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA issues to copy one cell, then offset, then continue

    Hello fourmurphys,

    This version of the macro worked in my tests.

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    05-23-2007
    Posts
    126

    Re: VBA issues to copy one cell, then offset, then continue

    Fantastic Leath, thank you so much!

    I'm truly always amazed by the generosity of folks in this forum... Thanks!

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA issues to copy one cell, then offset, then continue

    Hello fourmurphys,

    You're welcome. If you have any questions about what the code is doing, please ask.

  5. #5
    Forum Contributor
    Join Date
    05-23-2007
    Posts
    126

    Re: VBA issues to copy one cell, then offset, then continue

    Quote Originally Posted by Leith Ross View Post
    If you have any questions about what the code is doing, please ask.
    Actually... am curious about which part of the code is actually copy/pasting the value from column A into the SalesTbl range...?

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA issues to copy one cell, then offset, then continue

    Hello fourmurphys,

    The Order variable holds the value from column "A" for the current Cell in column "B".

    The row in the table that matches the Seller in column "B" is done by this line...
    Please Login or Register  to view this content.
    This line of code copies the Order into the table at the given Row.
    Please Login or Register  to view this content.
    SpecialCells returns a Range of Blank cells. The first cell in the group is the one where the Order will copied.

    Note: If SpecialCells fails to find any Blank Cells it will error. That is why the On Error statement is there.

  7. #7
    Forum Contributor
    Join Date
    05-23-2007
    Posts
    126

    Re: VBA issues to copy one cell, then offset, then continue

    Wow, thanks Leith! I'm super close to an epiphanal moment...
    for the row line of code:
    Please Login or Register  to view this content.
    The (1,1) makes me think it's offsetting 1 row and 1 column... but isn't?

  8. #8
    Registered User
    Join Date
    08-27-2019
    Location
    Alabama, USA
    MS-Off Ver
    365, 2016, 2010, 2007
    Posts
    57

    Re: VBA issues to copy one cell, then offset, then continue

    In my experience .cells(r, c) is referring to a cell located at row r and column c, the .value after it would then take the value of it. Therfore I would read the last part as making the value of A1 equal to the variable order.

    However, I'm not familiar with specialCells, so it may act differently.

    EDIT 15:47CST: Corrected a misspelling.

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA issues to copy one cell, then offset, then continue

    Hello fourmurphys,

    The SpecialCells returns a Range, in this case, of any blank cells in the SalesTbl.Rows(Row). This Range may or may not be contiguous. What we are interested in is the first blank cell in the returned Range of cells. To get that cell I use the Cells method to return the first cell in the first row and column of the SpecialCells Range.

  10. #10
    Forum Contributor
    Join Date
    05-23-2007
    Posts
    126

    Re: VBA issues to copy one cell, then offset, then continue

    Quote Originally Posted by Leith Ross View Post
    Hello fourmurphys,

    The SpecialCells returns a Range, in this case, of any blank cells in the SalesTbl.Rows(Row). This Range may or may not be contiguous. What we are interested in is the first blank cell in the returned Range of cells. To get that cell I use the Cells method to return the first cell in the first row and column of the SpecialCells Range.
    Thanks! Perfect.

+ 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. vba to copy certain elements in cell comments & copy to offset cell in same row
    By sureng20 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-24-2017, 11:03 PM
  2. OFFSET linking issues
    By usman153 in forum Excel General
    Replies: 1
    Last Post: 07-19-2017, 08:11 AM
  3. Replies: 1
    Last Post: 06-26-2017, 11:07 AM
  4. [SOLVED] copy value of a cell and cut/copy offset by 1 column and 1 row
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-29-2015, 12:57 PM
  5. SUM OFFSET Issues
    By FlyHigh1 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-15-2014, 09:59 AM
  6. Index - Offset - Match Issues
    By Ray Wright in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-03-2005, 02:05 AM
  7. Copy a cell to another cell and continue up to empty cell
    By hme in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-30-2005, 03:50 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