+ Reply to Thread
Results 1 to 2 of 2

Copy multiple ranges to different sheets and repeat on button click

  1. #1
    Registered User
    Join Date
    11-12-2012
    Location
    London,England
    MS-Off Ver
    Excel 2010
    Posts
    2

    Copy multiple ranges to different sheets and repeat on button click

    Hi

    I'm really "green", only been doing VBA, macros for a couple weeks, so I do apologise if this has been asked before.
    I need to copy two ranges of data in two different ways to two different sheets.
    I would also need the macro\VBA to enter data in the same rows in the next column for each worksheet.
    I have managed to extract the data and paste it into the relevant worksheets but, due to limited experience, I have been unable to get the repeat process going and new data is just pasted over the previous entry.

    The data is copied into excel through a program used for acquiring analysis of building materials via a clipboard/paste procedure.
    I would like the Macro\VBA to work in two parts
    Part 1
    Sheet 3 containing the data in range F2:F11 and H2:H11. (This will always be the same.)
    range F2:F11 is pasted into sheet 2 B2:B11 and H2:H11 is pasted into sheet 2 B14:B23

    Part 2
    cells B6 and B11 is copied to B25 and B26 respectively
    cells B18 and B23 is copied to B30 and B31 respectively
    c2 on sheet 2 should be set as active and sheet 3 is activated again

    Up to this point I have managed to get it to work.
    the problem for me starts with a new set of data.
    Data is acquired through the analysis program and pasted into sheet 3 (same F and H ranges)
    Macro\VBA should carry out same procedure as in part 1 and 2 but paste the data in c2 on sheet and repeat this procedure for every new set of data up to a maximum of 20 entries.

    Any help you guys could offer would be greatly appreciated.

    Thanks in advance

  2. #2
    Registered User
    Join Date
    11-12-2012
    Location
    London,England
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Copy multiple ranges to different sheets and repeat on button click

    Seen I picked up a couple of views.
    I manage to sort it out with the following code.
    Might be useful to someone else.

    Sub paste_pyrite_data()

    Dim ps As Worksheet, ds As Worksheet, col As Integer
    Dim rng As Range, rng1 As Range

    Set ds = Sheets("DATA")
    Set ps = Sheets("PYRITE")
    Set rng = ds.Range("F2:F11")
    Set rng1 = ds.Range("H2:H11")

    If ps.Range("B2").Value = "" Then
    col = 2
    ElseIf ps.Range("O2").Value <> "" Then
    Exit Sub
    Else
    col = ps.Range("O2").End(xlToLeft).Column + 1
    End If
    rng.Copy ps.Cells(2, col)
    rng1.Copy ps.Cells(14, col)
    Exit Sub

    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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