+ Reply to Thread
Results 1 to 8 of 8

Copying and pasting using SpecialCells in VBA

  1. #1
    Registered User
    Join Date
    12-12-2014
    Location
    Ottawa, Canada
    MS-Off Ver
    2013
    Posts
    8

    Copying and pasting using SpecialCells in VBA

    Hello, I'm a VBA beginner trying to copy all cells with data in the F column and paste them to their corresponding cells in the E column (which are all empty). Basically I want to shift all cells with data in F to the left one column. (This is for an export that dumps Excel data and the data for certain columns ends up getting split up between two columns and I'm trying to get it all back together in one.) The relevant code is below.

    I get "that command cannot be used on multiple selections" on the Paste line, and on the Copy line sometimes too (It was working a while ago and now it gives the error message too). I tried shifting the cells with offset but I get the same error message.

    Can anyone give me some ideas on how to proceed?

    Thanks!


    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copying and pasting using SpecialCells in VBA

    Should be

    rng2.SpecialCells(xlCellTypeBlanks).PasteSpecial xlValues

  3. #3
    Registered User
    Join Date
    12-12-2014
    Location
    Ottawa, Canada
    MS-Off Ver
    2013
    Posts
    8

    Re: Copying and pasting using SpecialCells in VBA

    Thanks AB33, any ideas on why the Copy line would be generating the error too?

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copying and pasting using SpecialCells in VBA

    Since you are selecting an entire column and if there are no constant, the code will error. You might think you have constants, but excel might think otherwise. You can test the column which has the constant by:

    CRTL+G
    Goto menu appears, then select Special- click constant and see if any of the cells are highlighted by excel. By the way, you need to select the range first.

  5. #5
    Registered User
    Join Date
    12-12-2014
    Location
    Ottawa, Canada
    MS-Off Ver
    2013
    Posts
    8

    Re: Copying and pasting using SpecialCells in VBA

    Thanks AB33, but I do have constants in F and I get the same message on the COPY line even if I select the range before. Any further ideas?

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copying and pasting using SpecialCells in VBA

    Sorry! I did not notice that you can not use it with multiple selection. You can do one column at a time.

  7. #7
    Registered User
    Join Date
    12-12-2014
    Location
    Ottawa, Canada
    MS-Off Ver
    2013
    Posts
    8

    Re: Copying and pasting using SpecialCells in VBA

    Any ideas on alternative ways to shift/move non empty cells over to the column to their left? Thanks.

  8. #8
    Registered User
    Join Date
    12-12-2014
    Location
    Ottawa, Canada
    MS-Off Ver
    2013
    Posts
    8

    Re: Copying and pasting using SpecialCells in VBA

    I think I was over-complicating things, I just wrote a simple for loop to copy values of non empty cells in F into the Cells in E, and it works fine.

+ 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. Copying & pasting a current region to another sheet w/o actually copying.....
    By Excel_vba in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-15-2014, 09:08 PM
  2. Using SpecialCells for multi-column same-row copy/pasting
    By evilgrinners in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-15-2013, 12:06 PM
  3. Copying and pasting?
    By awz1 in forum Excel General
    Replies: 1
    Last Post: 07-17-2012, 10:27 AM
  4. Autofiltering, copying cells and specialcells
    By jlt199 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-31-2010, 07:44 PM
  5. Copying and pasting
    By st3ady in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 11-10-2006, 03:47 PM
  6. Need Help with copying and pasting with var.
    By Mikeice in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-29-2005, 08:05 AM
  7. Problems copying Autofiltered rows & SpecialCells
    By Philip in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-19-2005, 04:06 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