+ Reply to Thread
Results 1 to 10 of 10

Cut and paste VBA

  1. #1
    Forum Contributor
    Join Date
    01-12-2004
    Location
    Nebraska, USA
    MS-Off Ver
    Office 365
    Posts
    167

    Cut and paste VBA

    Hi guys. Me again.....

    I'm new to VBA...(just started learning last year)...and everything that I learn, I learn mostly by trial and error...referring to a handful of VBA sourcebooks... and from the EXPERT advice and guidance I receive from this forum. There hasn't been a situation, yet, that you people haven't been able to resolve with brilliant suggestions and code construction.

    MY problem this time, is constructing VBA code for a Macro that I recorded with the Macro Recorder. Clearly, the Macro is NOT the most efficient way to accomplish the task that I need to perform...but I can barely begin to understand exactly how to construct VBA to perform this task. Here is the task:

    Suppose Sheet1!B1:??1 contain unique entries. (The [??] indicates that the last column with entries is unknown).
    Directly below that...[Sheet!B2:??2]..is another range of unique entries.

    What I need to do, is cut a pair of entries from each COLUMN, and paste them into one single column (A:A)...with a single row separating each pair of entries...like so:

    Item from B1
    Item from B2
    (Empty row)
    Item from C1
    Item from C2
    (Empty row)
    Item from D1
    Item from D2
    (Empty row)...etc.


    Simple enough...right?? (for you guys...!!!)
    I know I need to set DIM for multiple cut/paste operations...but aside from that...I don't how to continue.

    As usual...thanks, in advance, for your excellent suggestions.
    Each time you guys (and gals) help me out...I gain a little more insight into exactly HOW and WHY VBA works.
    Last edited by HuskerBronco; 09-08-2009 at 04:36 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Cut and paste VBA

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    01-12-2004
    Location
    Nebraska, USA
    MS-Off Ver
    Office 365
    Posts
    167

    Re: Cut and paste VBA

    Hi royUK...

    Here is the sample worksheet you suggested.
    Attached Files Attached Files

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437

    Re: Cut and paste VBA

    Something like this do.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  5. #5
    Forum Contributor
    Join Date
    01-12-2004
    Location
    Nebraska, USA
    MS-Off Ver
    Office 365
    Posts
    167

    Thumbs up Re: Cut and paste VBA

    That worked perfectly...Andy!!!
    And...I understand the purpose of each part of your code.
    Thank you for your quick, useful response.

  6. #6
    Forum Contributor
    Join Date
    01-12-2004
    Location
    Nebraska, USA
    MS-Off Ver
    Office 365
    Posts
    167

    Unhappy Re: Cut and paste VBA

    Whoops....!!!

    Andy's code worked perfect until I tried to run it UNDERNEATH some cells that are populated with an array formula.

    Then it kept telling me that I "couldn't change part of an array".

    I even changed the parameters of the code so that lngRow was set at 11...well below the array cells.

    Am I doing something wrong...???

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437

    Re: Cut and paste VBA

    I assume then that the formula in the first 2 rows actually contains an array formula spanning either more than 2 rows or more than 1 column.

    Does it make sense to copy the cell in this case? Should you not just copy the values.

  8. #8
    Forum Contributor
    Join Date
    01-12-2004
    Location
    Nebraska, USA
    MS-Off Ver
    Office 365
    Posts
    167

    Re: Cut and paste VBA

    Andy...

    Here's what I did...

    Instead of running your VBA on a NEW worksheet, I tried to run it on an existing worksheet.
    Attached is a condensed version of this worksheet.

    I was hoping to have the new range appear in the shaded cells.
    As you can see...those shaded cells ARE below an array.

    I adjusted your VBA as follows:

    1. Changed rngData start range from "B1" to "B9"
    2. I also changed lngRow from "1" to "9"

    I thought that would start the NEW range in cell A9...but, obviuosly...it doesn't...because it tries to change part of my array.

    Is there any way your VBA can be written to "skip" the cells containing the array?

    I have an entire worksheet that contains nothing but data for each week.
    The TOP 7 rows of this worksheet are populated...most of the way across...with arrays.
    Every week, I would like this new range to appear on this DATA worksheet.

    This is not a necessity...but, my other option is to create a separate worksheet strictly for this purpose.
    I'd like to avoid that. Any suggestions??
    Attached Files Attached Files

  9. #9
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437

    Re: Cut and paste VBA

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    01-12-2004
    Location
    Nebraska, USA
    MS-Off Ver
    Office 365
    Posts
    167

    Thumbs up Re: Cut and paste VBA

    Ahhhhh.....!!!!

    I changed the wrong parameter....!!!!

    Just when I thought I knew what I was doing...!!!

    Thanks, a bunch, Andy...!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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