+ Reply to Thread
Results 1 to 7 of 7

Copy data from certain cells automatically and then delete the data from 1st worksheet

Hybrid View

Bill01 Copy data from certain cells... 10-09-2013, 03:48 AM
OllieB Re: Copy data from certain... 10-09-2013, 04:37 AM
Bill01 Re: Copy data from certain... 10-09-2013, 04:57 AM
Bill01 Re: Copy data from certain... 10-09-2013, 05:32 AM
OllieB Re: Copy data from certain... 10-09-2013, 05:38 AM
Bill01 Re: Copy data from certain... 10-09-2013, 06:02 AM
OllieB Re: Copy data from certain... 10-09-2013, 06:12 AM
  1. #1
    Registered User
    Join Date
    10-09-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    10

    Copy data from certain cells automatically and then delete the data from 1st worksheet

    Hi I am new and i don't know much about macro's yet. Sorry for my grammar.

    I would like to import some date from a website. This i do manually (just copy paste). Then i would like to copy certain cells from this worksheet (1st worksheet) to other cells in another worksheet (2nd worksheet), so that i would only have the data i need and i would have my own lay-out. Finally i should be able to delete the imported data without this having an influence on the 2nd worksheet. I would like that excel does this automatically after i paste the imported data in my excel.

    Explanation:

    - cell C9 in 1st worksheet has a certain value.
    - column A in 2nd worksheet contains values of the same kind as cell C9 in 1st worksheet
    - A particular cell in column A from the 2nd worksheet has the exact same value as C9 in 1st worksheet.
    - Data from some cells in 1st worksheet (let's say:B3, G8, G9, F3) should be autmotically copied to certain cells in the relevant row in the 2nd worksheet
    - Data in 1st worksheet can now be deleted.
    - 2nd worksheets keeps this data.

    Thanks in advance

  2. #2
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Copy data from certain cells automatically and then delete the data from 1st worksheet

    Hi Bill,

    Please copy the below routine in the worksheet module of the worksheet where you are pasting the information - you will need to correct the name of the second worksheet (target for copy) and the cells being monitored (pasted into) and being copied

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    '#
    '# delare private variables
    '#
       Dim pvt_obj_MonitoringRange As Excel.Range
       Dim pvt_obj_FindRange As Excel.Range
       
    '#
    '# set the range to monitor to consist of the cells that are being changed by the paste operation which
    '# should trigger the copy action - additional cells to be monitoreed should be added to the below statement
    '# as the range object is also used to clear the appropriate fields on worksheet 1
    '#
       Set pvt_obj_MonitoringRange = Union(Range("C9"), Range("B3"), Range("G8"), Range("G9"), Range("F3"))
       
    '#
    '# check if one or more cells have changed that are part of the range to monitor - if so start the
    '# process of copying data
    '#
       If Not Intersect(Target, pvt_obj_MonitoringRange) Is Nothing Then
       
       '#
       '# attempt to find the row on worksheet 2 where the value in column A equals the value entered/pasted
       '# in cell C9 on this worksheet
       '#
          Set pvt_obj_FindRange = ThisWorkbook.Worksheets("Sheet2").Columns("A").Find(Target.Parent.Range("C9").Value)
          If pvt_obj_FindRange Is Nothing Then
             MsgBox "Unable to find argument " & Target.Parent.Range("C9").Value, vbCritical, "Not found"
             Exit Sub
          End If
          
       '#
       '# update the data on the second worksheet - the column offset refers to column A where the search was
       '# conducted - so offset value 1 = column B, value 2 - column C etc
       '#
          With pvt_obj_FindRange
             .Offset(0, 1).Value = Target.Parent.Range("B3").Value             '# writes value B3 to B column on worksheet 2
             .Offset(0, 2).Value = Target.Parent.Range("G8").Value             '# writes value G8 to C column on worksheet 2
             .Offset(0, 3).Value = Target.Parent.Range("G9").Value             '# writes value G9 to D column on worksheet 2
             .Offset(0, 4).Value = Target.Parent.Range("F3").Value             '# writes value F3 to E column on worksheet 2
          End With
       
       '#
       '# clear the fields that are part of the monitoring range - disable the Excel event model to avoid
       '# this action from triggering this routine itself again
       '#
          Application.EnableEvents = False
          pvt_obj_MonitoringRange.ClearContents
          Application.EnableEvents = True
          
       End If
    
    End Sub
    If you like my contribution click the star icon!

  3. #3
    Registered User
    Join Date
    10-09-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Copy data from certain cells automatically and then delete the data from 1st worksheet

    i will look into it. Thanks!

  4. #4
    Registered User
    Join Date
    10-09-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Copy data from certain cells automatically and then delete the data from 1st worksheet

    It doesn't work. Is it because i have a dutch version of excel?

    Also i have changed the cell names to test and simplify the code. The 2nd worksheet is called 'Objecten'

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    '#
    '# delare private variables
    '#
       Dim pvt_obj_MonitoringRange As Excel.Range
       Dim pvt_obj_FindRange As Excel.Range
       
    '#
    '# set the range to monitor to consist of the cells that are being changed by the paste operation which
    '# should trigger the copy action - additional cells to be monitoreed should be added to the below statement
    '# as the range object is also used to clear the appropriate fields on worksheet 1
    '#
       Set pvt_obj_MonitoringRange = Union(Range("F3"), Range("N13"))
       
    '#
    '# check if one or more cells have changed that are part of the range to monitor - if so start the
    '# process of copying data
    '#
       If Not Intersect(Target, pvt_obj_MonitoringRange) Is Nothing Then
       
       '#
       '# attempt to find the row on worksheet 2 where the value in column A equals the value entered/pasted
       '# in cell C9 on this worksheet
       '#
          Set pvt_obj_FindRange = ThisWorkbook.Worksheets("Objecten").Columns("A").Find(Target.Parent.Range("F3").Value)
          If pvt_obj_FindRange Is Nothing Then
             MsgBox "Unable to find argument " & Target.Parent.Range("F3").Value, vbCritical, "Not found"
             Exit Sub
          End If
          
       '#
       '# update the data on the second worksheet - the column offset refers to column A where the search was
       '# conducted - so offset value 1 = column B, value 2 - column C etc
       '#
          With pvt_obj_FindRange
             .Offset(0, 22).Value = Target.Parent.Range("N13").Value             '# writes value B3 to B column on worksheet 2
          End With
       
       '#
       '# clear the fields that are part of the monitoring range - disable the Excel event model to avoid
       '# this action from triggering this routine itself again
       '#
          Application.EnableEvents = False
          pvt_obj_MonitoringRange.ClearContents
          Application.EnableEvents = True
          
       End If
    
    End Sub
    Sub Import_van_taxatiekaart()
    
    End Sub

  5. #5
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Copy data from certain cells automatically and then delete the data from 1st worksheet

    Bill,

    Ducth version has nothing to do with it. I copied the your revised code into an empty workbook under worksheet Sheet1. I then renamed worksheet Sheet2 to "Objecten" and entered values in cells F3 and N13 on worksheet Sheet3. When I copy the range A1:N13 from Sheet3 to Sheet1, the routine gets triggered and copies the value of N13 to column W on worksheets Objecten.

    I believe this is exactly what you asked for. Please see attached test workbook
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    10-09-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Copy data from certain cells automatically and then delete the data from 1st worksheet

    I got it. You're a boss! thanks man!

  7. #7
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Copy data from certain cells automatically and then delete the data from 1st worksheet

    You are welcome. Please feel free to click on the star icon ("Add Reputation") if you are happy with my contribution.

+ 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. [SOLVED] Copy row of data, paste in another worksheet, delete some of the cells copied
    By dev111ski in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-14-2012, 05:58 PM
  2. automatically copy data from one worksheet to another
    By LC in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 PM
  3. automatically copy data from one worksheet to another
    By Dave Peterson in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-06-2005, 11:05 AM
  4. automatically copy data from one worksheet to another
    By LC in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 AM
  5. [SOLVED] automatically copy data from one worksheet to another
    By LC in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-22-2005, 11:05 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