Ask Experts Questions for FREE Help !
Ask
    kvinay_00's Avatar
    kvinay_00 Posts: 36, Reputation: 1
    Junior Member
     
    #1

    Aug 8, 2013, 07:27 PM
    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
    Attached Files
  1. File Type: zip Book1.zip (8.7 KB, 25 views)
  2. JBeaucaire's Avatar
    JBeaucaire Posts: 5,426, Reputation: 997
    Software Expert
     
    #2

    Aug 16, 2013, 01:54 PM
    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.
    kvinay_00's Avatar
    kvinay_00 Posts: 36, Reputation: 1
    Junior Member
     
    #3

    Aug 20, 2013, 08:59 PM
    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
    JBeaucaire's Avatar
    JBeaucaire Posts: 5,426, Reputation: 997
    Software Expert
     
    #4

    Aug 21, 2013, 11:52 PM
    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

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Need code to export the data in TXT file by VB 6.0 [ 5 Answers ]

Please help me, I need code to export the data in TXT file by VB 6.0. Need a fixed length for columns so that data cannot be merged.Thank in advance for your help.

Macro to select a value in the range of cells? [ 7 Answers ]

I need a macro that will select every cell in a range based on a number in a cell. If the number in the cell (in this case the cell is b2,b5,b10 and b15) is 0 then I want to select cell b2,b5,b10,b15 in the range b1:b50 Thanks for the help!

Excel Macro Out of Cells [ 9 Answers ]

I have an excel macro that keeps coming up with the error message that it is out of cells. I am wondering if there is anything I can do?

Macro to print a page-or not, based on a cells content. [ 2 Answers ]

Sub Printing() ' ' Printing Macro ' Macro recorded 15/12/2005 by Lenah ' ' Keyboard Shortcut: Ctrl+p ' Application.ScreenUpdating = False Sheets("Invoice").Select ActiveWindow.SelectedSheets.PrintOut Copies:=4, Collate:=True


View more questions Search