Closed Thread
Results 1 to 10 of 10

copy and paste multiple selection

  1. #1
    Gareth
    Guest

    copy and paste multiple selection

    Have had a look in Help but not able to find an answer to my problem, in
    fact Help says that what I want is not possible so I thought I would turn to
    the pro's.

    I want to copy a selection of cells and paste them into a row on another
    sheet.

    An example would be to copy:

    Sheets("Sheet1").Range("T5,C7:T9,T13,C15:T17,T19,C21:T23")

    and put it into A4:F4 on Sheet2

    I know I can do it one cell at a time but I was hoping that I could speed
    things up and do it all in one go as the macro will be quite long.

    Thanks in advance.

    Gareth



  2. #2
    Greg Wilson
    Guest

    RE: copy and paste multiple selection

    Try this ( Be advised I'm not a pro):

    Sub TransferData()
    Dim SourceRng As Range, DestRng As Range
    Dim c As Range
    Dim Prompt As String, Title As String, Default As String
    Dim i As Integer

    Prompt = "Select source range..."
    Title = "Data transfer"
    Default = Selection.Address
    On Error Resume Next
    Set SourceRng = Application.InputBox(Prompt, Title, Default, Type:=8)
    If Err.Number > 0 Then Exit Sub
    Prompt = "Select destination cell..."
    Set DestRng = Application.InputBox(Prompt, Title, Type:=8)
    If Err.Number > 0 Then Exit Sub
    On Error GoTo 0
    i = 0
    Application.ScreenUpdating = False
    For Each c In SourceRng
    i = i + 1
    DestRng(1, i) = c.Value
    Next
    'DestRng.Parent.Activate
    Application.ScreenUpdating = True
    End Sub

    Regards,
    Greg


    "Gareth" wrote:

    > Have had a look in Help but not able to find an answer to my problem, in
    > fact Help says that what I want is not possible so I thought I would turn to
    > the pro's.
    >
    > I want to copy a selection of cells and paste them into a row on another
    > sheet.
    >
    > An example would be to copy:
    >
    > Sheets("Sheet1").Range("T5,C7:T9,T13,C15:T17,T19,C21:T23")
    >
    > and put it into A4:F4 on Sheet2
    >
    > I know I can do it one cell at a time but I was hoping that I could speed
    > things up and do it all in one go as the macro will be quite long.
    >
    > Thanks in advance.
    >
    > Gareth
    >
    >
    >


  3. #3
    Jim Cone
    Guest

    Re: copy and paste multiple selection

    Gareth,

    You can't put 10 lbs in a 5 lb bag.

    There are 165 cells in...
    Range("T5,C7:T9,T13,C15:T17,T19,C21:T23")
    and
    6 cells in...
    Range("A4:F4")

    Your can do this...
    Sheets("Sheet2").Range("A4:F4").Value = Sheets("Sheet1").Range("G4:L4").Value

    Regards,
    Jim Cone
    San Francisco, USA


    "Gareth" <[email protected]> wrote in message
    news:[email protected]...
    > Have had a look in Help but not able to find an answer to my problem, in
    > fact Help says that what I want is not possible so I thought I would turn to
    > the pro's.
    > I want to copy a selection of cells and paste them into a row on another
    > sheet.
    > An example would be to copy:
    >
    > Sheets("Sheet1").Range("T5,C7:T9,T13,C15:T17,T19,C21:T23")
    >
    > and put it into A4:F4 on Sheet2
    >
    > I know I can do it one cell at a time but I was hoping that I could speed
    > things up and do it all in one go as the macro will be quite long.
    > Thanks in advance.
    > Gareth



  4. #4
    Dave Peterson
    Guest

    Re: copy and paste multiple selection

    There are 165 cells in:
    Sheets("Sheet1").Range("T5,C7:T9,T13,C15:T17,T19,C21:T23")

    And 6 cells in A4:F4.

    Isn't that a problem?



    Gareth wrote:
    >
    > Have had a look in Help but not able to find an answer to my problem, in
    > fact Help says that what I want is not possible so I thought I would turn to
    > the pro's.
    >
    > I want to copy a selection of cells and paste them into a row on another
    > sheet.
    >
    > An example would be to copy:
    >
    > Sheets("Sheet1").Range("T5,C7:T9,T13,C15:T17,T19,C21:T23")
    >
    > and put it into A4:F4 on Sheet2
    >
    > I know I can do it one cell at a time but I was hoping that I could speed
    > things up and do it all in one go as the macro will be quite long.
    >
    > Thanks in advance.
    >
    > Gareth


    --

    Dave Peterson

  5. #5
    Gareth
    Guest

    Re: copy and paste multiple selection

    c7:c9, etc, are merged cells if that makes ant difference........

    "Jim Cone" <[email protected]> wrote in message
    news:[email protected]...
    > Gareth,
    >
    > You can't put 10 lbs in a 5 lb bag.
    >
    > There are 165 cells in...
    > Range("T5,C7:T9,T13,C15:T17,T19,C21:T23")
    > and
    > 6 cells in...
    > Range("A4:F4")
    >
    > Your can do this...
    > Sheets("Sheet2").Range("A4:F4").Value =

    Sheets("Sheet1").Range("G4:L4").Value
    >
    > Regards,
    > Jim Cone
    > San Francisco, USA
    >
    >
    > "Gareth" <[email protected]> wrote in message
    > news:[email protected]...
    > > Have had a look in Help but not able to find an answer to my problem, in
    > > fact Help says that what I want is not possible so I thought I would

    turn to
    > > the pro's.
    > > I want to copy a selection of cells and paste them into a row on another
    > > sheet.
    > > An example would be to copy:
    > >
    > > Sheets("Sheet1").Range("T5,C7:T9,T13,C15:T17,T19,C21:T23")
    > >
    > > and put it into A4:F4 on Sheet2
    > >
    > > I know I can do it one cell at a time but I was hoping that I could

    speed
    > > things up and do it all in one go as the macro will be quite long.
    > > Thanks in advance.
    > > Gareth

    >




  6. #6
    Greg Wilson
    Guest

    Re: copy and paste multiple selection

    Gareth,
    If you have merged cells then you need to replace my macro with this. Please
    advise if it works for you or not.

    Sub TransferData()
    Dim SourceRng As Range, DestRng As Range
    Dim c As Range
    Dim Prompt As String, Title As String, Default As String
    Dim i As Integer

    Prompt = "Select source range..."
    Title = "Data transfer"
    Default = Selection.Address
    On Error Resume Next
    Set SourceRng = Application.InputBox(Prompt, Title, Default, Type:=8)
    If Err.Number > 0 Then Exit Sub
    Prompt = "Select destination cell..."
    Set DestRng = Application.InputBox(Prompt, Title, Type:=8)
    If Err.Number > 0 Then Exit Sub
    On Error GoTo 0
    i = 0
    Application.ScreenUpdating = False
    For Each c In SourceRng.Cells
    If Len(c) > 0 Then
    i = i + 1
    DestRng(1, i) = c
    End If
    Next
    Application.ScreenUpdating = True
    End Sub

    Regards,
    Greg

    "Gareth" wrote:

    > c7:c9, etc, are merged cells if that makes ant difference........
    >
    > "Jim Cone" <[email protected]> wrote in message
    > news:[email protected]...
    > > Gareth,
    > >
    > > You can't put 10 lbs in a 5 lb bag.
    > >
    > > There are 165 cells in...
    > > Range("T5,C7:T9,T13,C15:T17,T19,C21:T23")
    > > and
    > > 6 cells in...
    > > Range("A4:F4")
    > >
    > > Your can do this...
    > > Sheets("Sheet2").Range("A4:F4").Value =

    > Sheets("Sheet1").Range("G4:L4").Value
    > >
    > > Regards,
    > > Jim Cone
    > > San Francisco, USA
    > >
    > >
    > > "Gareth" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > Have had a look in Help but not able to find an answer to my problem, in
    > > > fact Help says that what I want is not possible so I thought I would

    > turn to
    > > > the pro's.
    > > > I want to copy a selection of cells and paste them into a row on another
    > > > sheet.
    > > > An example would be to copy:
    > > >
    > > > Sheets("Sheet1").Range("T5,C7:T9,T13,C15:T17,T19,C21:T23")
    > > >
    > > > and put it into A4:F4 on Sheet2
    > > >
    > > > I know I can do it one cell at a time but I was hoping that I could

    > speed
    > > > things up and do it all in one go as the macro will be quite long.
    > > > Thanks in advance.
    > > > Gareth

    > >

    >
    >
    >


  7. #7
    Jim Cone
    Guest

    Re: copy and paste multiple selection

    Gareth,

    Yes it does. The following works...
    '------------------
    Sub Test()
    Dim rngA As Excel.Range
    Dim lngN As Long

    Set rngA = Range("T5,C7:T9,T13,C15:T17,T19,C21:T23")

    For lngN = 1 To rngA.Areas.Count
    Range("A4")(1, lngN).Value = rngA.Areas(lngN)(1).Value
    Next
    Set rngA = Nothing
    End Sub
    '-----------------------

    Jim Cone
    San Francisco, USA



    "Gareth" <[email protected]> wrote in message
    news:[email protected]...
    > c7:c9, etc, are merged cells if that makes ant difference........




    > "Jim Cone" <[email protected]> wrote in message
    > news:[email protected]...
    > > Gareth,
    > > You can't put 10 lbs in a 5 lb bag.
    > > There are 165 cells in...
    > > Range("T5,C7:T9,T13,C15:T17,T19,C21:T23")
    > > and
    > > 6 cells in...
    > > Range("A4:F4")
    > > Your can do this...
    > > Sheets("Sheet2").Range("A4:F4").Value =

    > Sheets("Sheet1").Range("G4:L4").Value
    > > Regards,
    > > Jim Cone
    > > San Francisco, USA



  8. #8
    Greg Wilson
    Guest

    Re: copy and paste multiple selection

    Jim,

    My read when Gareth said C7:C9 (instead of C7:T9) are merged cells was that
    the columns of cells within the contiguous ranges were merged independantly -
    i.e. C7:C9 are one merged range and D7:D9 another etc. Your interpretation
    makes more sence for the particular example because the number of areas
    matches the cells in A4:F4. However, he did indicate that this was only an
    example, leaving the possibility of there being multiple merged ranges or
    just multiple cells within contiguous blocks. Therefore, use of Areas would
    not work. Obviously, what is needed is more insight from Gareth. Thought I'd
    point out my interpretation before moving on.

    Regards,
    Greg

    "Jim Cone" wrote:

    > Gareth,
    >
    > Yes it does. The following works...
    > '------------------
    > Sub Test()
    > Dim rngA As Excel.Range
    > Dim lngN As Long
    >
    > Set rngA = Range("T5,C7:T9,T13,C15:T17,T19,C21:T23")
    >
    > For lngN = 1 To rngA.Areas.Count
    > Range("A4")(1, lngN).Value = rngA.Areas(lngN)(1).Value
    > Next
    > Set rngA = Nothing
    > End Sub
    > '-----------------------
    >
    > Jim Cone
    > San Francisco, USA
    >
    >
    >
    > "Gareth" <[email protected]> wrote in message
    > news:[email protected]...
    > > c7:c9, etc, are merged cells if that makes ant difference........

    >
    >
    >
    > > "Jim Cone" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > Gareth,
    > > > You can't put 10 lbs in a 5 lb bag.
    > > > There are 165 cells in...
    > > > Range("T5,C7:T9,T13,C15:T17,T19,C21:T23")
    > > > and
    > > > 6 cells in...
    > > > Range("A4:F4")
    > > > Your can do this...
    > > > Sheets("Sheet2").Range("A4:F4").Value =

    > > Sheets("Sheet1").Range("G4:L4").Value
    > > > Regards,
    > > > Jim Cone
    > > > San Francisco, USA

    >
    >


  9. #9
    Registered User
    Join Date
    01-13-2010
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    1

    Question Convert multiple selection to values

    I'm using excel 2007.
    I would like to convert multiple selections of cells (each cell has a furmula) to values.
    I tried to do this by: selecting the multiple cells==> copy==>paste special==> values, but I get the error message "The command can not be used on multiple selections.".
    I assume this can be done with a macro?
    Thanks you, Alon.

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: copy and paste multiple selection

    alo.shav,

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread.

Closed 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