Results 1 to 8 of 8
  1. #1
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Hatsukaichi, Hiroshima, Japan
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Copying formatted cells to the clipboard (Excel 97)

    Hello, this is a very tall order, but is it possible to create a vba macro that will copy the contents of a column to the clipboard and ignore all cells that do not have a coloured background? I have created conditional formatting that colours all the cells containing a particular text sky blue. Here's the formula I'm using:

    =SEARCH($A$3, C3, 1)> 0

    I know how to select cells containing particular formatting but when I try to copy them I get an error message. It seems Excel won't copy multiple selections. I'd be grateful if someone would tell me how to do this using VBA or at least tell me if it isn't possible.

    Thank you very much,

    Chris (Hunt)

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copying formatted cells to the clipboard (Excel 97)

    You could filter the column using the same criteria as the conditional formatting and copy the filtered column?
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Hatsukaichi, Hiroshima, Japan
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copying formatted cells to the clipboard (Exce

    Thanks for the reply, sorry I don't understand your answer. Actually I wasn't clear. I have multiple selections in a column I want to cut them to the clipboard. Excel will let me copy the cells to another area of the worksheet but it won't let me cut the cells. I get the message:

    "The command you have selected cannot be performed with multiple selections.
    Select a single range and click the command again."

    It doesn't seem to be very easy to move cells except groups at a time.

    Chris (Hunt)

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Copying formatted cells to the clipboard (Exce

    Probably easier to copy them and then clear the original cells, I would think, or are other cells linked to them?
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Hatsukaichi, Hiroshima, Japan
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copying formatted cells to the clipboard (Exce

    Thanks, that is what I've just done using two separate macros. The first selects the cells, names them as a range (aacut) and then copies them. I manually paste them to where I want. The second reselects the name range and then I can delete it manually. I could automate the delete and probably will do so once I get used to working with the macros. This works because I'm selecting cells within a single column. In case anyone is interested here are the macros, I've assigned them to buttons for easy access:

    ------------------------------------------------

    Sub aacopy()

    SendKeys "%indaacut~", True
    SendKeys "^c", True

    End Sub

    Sub aacut()

    SendKeys "^g", False
    SendKeys "aacut~", True

    End Sub

    ------------------------------------------------

    I 'm still surprised it 's not easier to move a multiple selection of cells.

    Chris (Hunt)

  6. #6
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Copying formatted cells to the clipboard (Exce

    Can I ask why you are using SendKeys? It should only ever be used as a last resort in my opinion - it's much better to work with the actual Excel Object Model - e.g.:
    <pre>With Selection
    .Name = "aacut"
    .Copy
    End With</pre>

    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Hatsukaichi, Hiroshima, Japan
    Posts
    904
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copying formatted cells to the clipboard (Exce

    Thanks Rory, the reason I used sendkeys is simply because I could get it to work! Ill try again with the method you suggest. I agree that it is best to avoid send keys. Would you know how to get the macro to wait until I had copied the selection before continuing? That way I combine both separate macros into one.

    Cheers,

    Chris

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Copying formatted cells to the clipboard (Exce

    You can use Application.InputBox with Type:=8 to let the user specify a range in a macro:
    <code>
    Dim rng As Range
    Set rng = Application.InputBox(Prompt:="Please select a range", Type:=8)
    ' do something with the range
    ...</code>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •