Results 1 to 6 of 6

Thread: Excel macro

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0

    Excel macro

    Hi Everyone,

    I have an excel sheet (2010) which has raw data. I want to copy only certain bits of data into another sheet segregating the data.

    I have attached the sample file

    The data has to be taken from Raw data and copied in the sheet Macro-data as per the required fields until last empty cell.

    Need 2 such macros for different types of data.

    Raw data to be copied in the sheet Macro-data ---------> 1st Macro copy paste
    Raw data1 and copied in the sheet Macro-data1 -------> 2nd Macro copy paste

    Regards

    Umesh
    Attached Files Attached Files

  2. #2
    Junior Member
    Join Date
    Aug 2013
    Posts
    18
    Rep Power
    0
    Please find customised code for you.

    Hope this will help you.
    Code:
    Option Explicit
    Sub Rawdata()
    Dim data(10) As String
    Dim cnt, start, i, end_a, r_macro_data As Integer
    
        For cnt = 2 To ThisWorkbook.Sheets("raw data").Range("A1").End(xlDown).Row
            r_macro_data = ThisWorkbook.Sheets("Macro-data").Range("A1").End(xlDown).Row + 1
            ThisWorkbook.Sheets("Macro-data").Cells(r_macro_data, 1) = ThisWorkbook.Sheets("Raw Data").Cells(cnt, 1).Value
            start = 1
            For i = 1 To 5
                With ThisWorkbook.Sheets("Raw Data")
                    start = InStr(start, .Cells(cnt, 2).Value, ":") + 2
                    end_a = InStr(start, .Cells(cnt, 2).Value, Chr(10)) - 1
                    If end_a = -1 Then end_a = Len(ThisWorkbook.Sheets("Raw Data").Cells(cnt, 2).Value) + 1
                    If start = 2 Then start = end_a
                    data(i) = Mid(.Cells(cnt, 2).Value, start, end_a - start)
                End With
                ThisWorkbook.Sheets("Macro-data").Cells(r_macro_data, 1 + i) = data(i)
            Next i
        ThisWorkbook.Sheets("Macro-data").Cells(r_macro_data, 7) = ThisWorkbook.Sheets("Raw Data").Cells(cnt, 3).Value
        Next cnt
    End Sub
    
    
    Sub Rawdata1()
    Dim data(10) As String
    Dim cnt, start, i, end_a, r_macro_data As Integer
    
        For cnt = 2 To ThisWorkbook.Sheets("raw data 1").Range("A1").End(xlDown).Row
            r_macro_data = ThisWorkbook.Sheets("Macro-data 1").Range("A1").End(xlDown).Row + 1
            ThisWorkbook.Sheets("Macro-data 1").Cells(r_macro_data, 1) = ThisWorkbook.Sheets("Raw Data 1").Cells(cnt, 1).Value
            start = 1
            For i = 1 To 3
                With ThisWorkbook.Sheets("Raw Data 1")
                    start = InStr(start, .Cells(cnt, 2).Value, ":") + 2
                    end_a = InStr(start, .Cells(cnt, 2).Value, Chr(10)) - 1
                    If end_a = -1 Then end_a = Len(ThisWorkbook.Sheets("Raw Data 1").Cells(cnt, 2).Value) + 1
                    If start = 2 Then start = end_a
                    data(i) = Mid(.Cells(cnt, 2).Value, start, end_a - start)
                End With
                ThisWorkbook.Sheets("Macro-data 1").Cells(r_macro_data, 1 + i) = data(i)
            Next i
        Next cnt
    End Sub

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0

    Help

    Thank you for all your help.

    It was really helpfull.

    Need help with this two macros. I have created two excel file for it.

    Macro file
    Macro file 1

    Earlier i had taken help for almost similar kind of data for macro file 1 but now this time the there is a slight difference in the data.

    It has phone number instead of city.

    Please find the below link from which i had taken help to complete my work.

    http://www.mrexcel.com/forum/excel-questions/728709-copy-paste-macro-excel.html

    Thanks a ton for helping me.

    Please help me.

    Regards
    Umesh
    Attached Files Attached Files

  4. #4
    Junior Member
    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0
    Need help....Aju Thomas please help
    Last edited by knockme2; 10-18-2013 at 11:48 AM.

  5. #5
    Junior Member
    Join Date
    Aug 2013
    Posts
    18
    Rep Power
    0
    Code:
    Option Explicit
    Sub Rawdata()
    Dim data(10) As String
    Dim cnt, start, i, end_a, r_macro_data As Integer
    
        For cnt = 2 To ThisWorkbook.Sheets("raw data 1").Range("A1").End(xlDown).Row
            i = 0
            r_macro_data = ThisWorkbook.Sheets("Macro-data 1").Range("A1").End(xlDown).Row + 1
            ThisWorkbook.Sheets("Macro-data 1").Cells(r_macro_data, 1) = ThisWorkbook.Sheets("Raw Data 1").Cells(cnt, 1).Value
            start = 1
                With ThisWorkbook.Sheets("Raw Data 1")
                    start = InStr(start, .Cells(cnt, 2).Value, ":") + 2
                    end_a = InStr(start, .Cells(cnt, 2).Value, Chr(10)) - 1
                    If end_a = -1 Then end_a = Len(ThisWorkbook.Sheets("Raw Data 1").Cells(cnt, 2).Value) + 1
                    If start = 2 Then start = end_a
                    data(i) = Mid(.Cells(cnt, 2).Value, start, end_a - start)
                End With
                ThisWorkbook.Sheets("Macro-data 1").Cells(r_macro_data, 2 + i) = data(i)
            
            For i = 1 To 3
                With ThisWorkbook.Sheets("Raw Data 1")
                    start = InStr(start, .Cells(cnt, 2).Value, ":")
                    start = InStr(start, .Cells(cnt, 2).Value, Chr(10)) + 1
                    end_a = InStr(start, .Cells(cnt, 2).Value, Chr(10))
                    If end_a = 0 Then end_a = Len(ThisWorkbook.Sheets("Raw Data 1").Cells(cnt, 2).Value) + 1
                    If start = 2 Then start = end_a
                    data(i) = Mid(.Cells(cnt, 2).Value, start, end_a - start)
                End With
                ThisWorkbook.Sheets("Macro-data 1").Cells(r_macro_data, 2 + i) = data(i)
            Next i
        
        
                With ThisWorkbook.Sheets("Raw Data 1")
                    start = InStr(start, .Cells(cnt, 2).Value, ":") + 2
                    end_a = InStr(start, .Cells(cnt, 2).Value, Chr(10)) - 1
                    If end_a = -1 Then end_a = Len(ThisWorkbook.Sheets("Raw Data 1").Cells(cnt, 2).Value) + 1
                    If start = 2 Then start = end_a
                    data(i) = Mid(.Cells(cnt, 2).Value, start, end_a - start)
                End With
                ThisWorkbook.Sheets("Macro-data 1").Cells(r_macro_data, 2 + i) = data(i)
                
        ThisWorkbook.Sheets("Macro-data 1").Cells(r_macro_data, 7) = ThisWorkbook.Sheets("Raw Data 1").Cells(cnt, 3).Value
        Next cnt
    End Sub

  6. #6
    Junior Member
    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0
    Many Thanks Aju

Similar Threads

  1. Replies: 1
    Last Post: 09-29-2013, 12:02 AM
  2. Replies: 6
    Last Post: 09-24-2013, 04:13 PM
  3. Macro To Insert Columns In Excel
    By jac3130 in forum Excel Help
    Replies: 2
    Last Post: 05-17-2013, 07:49 AM
  4. Excel Macro Functions (GET.DOCUMENT)
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 2
    Last Post: 06-29-2011, 08:10 PM
  5. Excel Macro Functions (GET.CELL)
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 1
    Last Post: 05-17-2011, 08:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •