Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Spreadsheets (https://www.askmehelpdesk.com/forumdisplay.php?f=395)
-   -   Macro to export data from certain cells (https://www.askmehelpdesk.com/showthread.php?t=761868)

  • Aug 8, 2013, 07:27 PM
    kvinay_00
    1 Attachment(s)
    Macro to export data from certain cells
    Hello,
    I have a sheet (sheet1) which is used by different users many times to create some documents.
    After creating the document, the data entered is deleted and new data is entered.
    I want to capture information from certain cells each time to another sheet (sheet2) and data should remain there even if the data in sheet1 is deleted for new data entry.
    The new data entered should get added to sheet2 below first data and so on.
    I have attached a sample sheet.
    Can anybody help?
    Thanks in advance
  • Aug 16, 2013, 01:54 PM
    JBeaucaire
    1) Right-click on the EXPORT DATA button and select ASSIGN MACRO
    2) Click on NEW
    3) Paste in this macro:
    Code:

    Sub Rectangle3_Click()
    Dim NR As Long

    With Sheets("Sheet2")
        NR = .Range("A" & .Rows.Count).End(xlUp).Row + 1
        .Range("A" & NR).Value = Sheets("Sheet1").Range("B1").Value
        .Range("B" & NR).Value = Sheets("Sheet1").Range("E1").Value
        .Range("C" & NR).Value = Sheets("Sheet1").Range("E4").Value
    End With

    End Sub

    4) Close the editor.

    That should do it.
  • Aug 20, 2013, 08:59 PM
    kvinay_00
    Thank you so much JBeaucaire.
    One more help -
    The data is captured correctly. However, it allows duplicate entry of data.

    country model chassis no
    Kenya 10.75 1111
    Sudan 10.85 2222
    Kenya 10.75 1111
    Sudan 10.85 2222

    I want like if the data with a combination is already available in the rows above, it should not get copied again on new row.
    Thanks
  • Aug 21, 2013, 11:52 PM
    JBeaucaire
    This should do it:

    Code:

    Option Explicit

    Sub TransferData()
    Dim NR As Long

    With Sheets("Sheet2")
        .AutoFilterMode = False
        .Rows(1).AutoFilter 1, Sheets("Sheet1").Range("B1").Value
        .Rows(1).AutoFilter 2, Sheets("Sheet1").Range("E1").Value
        .Rows(1).AutoFilter 3, Sheets("Sheet1").Range("E4").Value
        NR = .Range("A" & .Rows.Count).End(xlUp).Row
        If NR = 1 Then
            .AutoFilterMode = False
            NR = .Range("A" & .Rows.Count).End(xlUp).Row + 1
            .Range("A" & NR).Value = Sheets("Sheet1").Range("B1").Value
            .Range("B" & NR).Value = Sheets("Sheet1").Range("E1").Value
            .Range("C" & NR).Value = Sheets("Sheet1").Range("E4").Value
        Else
            .AutoFilterMode = False
            MsgBox "This Data Exists in Sheet2 already"
        End If
    End With

    End Sub


  • All times are GMT -7. The time now is 11:35 AM.