Forum Discussion

LauraDaisy's avatar
LauraDaisy
Copper Contributor
May 01, 2018

Sorting data

hi, this is my data (theres 707 lines in total)

Transaction Status

Transaction ID

Transaction Date

RD Reference

Amount

Declined - Bank declined

10

01/11/2017

119664

20.00

Declined - Bank declined

11

01/12/2017

119664

20.00

Declined - Bank declined

12

01/01/2018

119664

20.00

Declined - Bank declined

13

01/02/2018

119664

20.00

Declined - Bank declined

14

01/03/2018

119658

20.00

Declined - Bank declined

15

01/04/2018

119658

20.00

Declined - Insufficient funds

16

01/09/2017

119658

20.00

Declined - Insufficient funds

17

01/10/2017

119658

20.00

Declined - Insufficient funds

18

01/09/2017

119665

20.00

Declined - Insufficient funds

19

01/09/2017

119666

20.00

Declined - Insufficient funds

20

07/09/2017

119730

20.00

Declined - Insufficient funds

21

07/10/2017

119730

20.00

Declined - Insufficient funds

22

07/11/2017

119730

20.00

Declined - Insufficient funds

23

07/12/2017

119725

20.00

Declined - Insufficient funds

24

07/01/2018

119725

20.00

Declined - Insufficient funds

25

07/02/2018

119725

20.00

Declined - Insufficient funds

26

07/03/2018

119725

20.00

Declined - Insufficient funds

27

28/09/2017

119737

20.00

 

i need to sort it for a CSV file import.

 

Each CSV file cannot have duplicate references - is there a quick way to do this.

 

Fingers crossed as I'm currently having to manually move each reference to new worksheet.

13 Replies

  • Hi LauraDaisy

     

    I almost done. Minor correction is required. 

     

    Sub M()
    Dim a, b, c As Double
    c = 0
    b = Range("A1048576").End(xlUp).Row
    For a = b To 2 Step -1
    Range("D" & a).Select
    If Range("D" & a).Value <> Range("D" & a - 1).Value Then
    c = c + 1
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlToLeft)).Select
    Selection.Copy
    Workbooks.Add
    Range("A1").Value = "Transaction Status"
    Range("B1").Value = "Transaction ID"
    Range("C1").Value = "Transaction Date"
    Range("D1").Value = "RD Reference"
    Range("E1").Value = "Amount"

    Range("A2").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False

    ActiveWorkbook.SaveAs Filename:="C:\Users\sense soft\Documents\Book" & c, FileFormat:=xlCSV, CreateBackup:=False
    ActiveWorkbook.Close
    ActiveCell.Offset(-1, 0).Select
    ActiveCell.Offset(1, 0).Select
    Selection.EntireRow.Insert
    ActiveCell.Offset(-1, 0).Select
    End If
    Next a
    End Sub
    • LauraDaisy's avatar
      LauraDaisy
      Copper Contributor

      So I tried  this (thankyou v.much :) Logaraj Sekar )

       

      I tried it on a new set of data - it worked but pulled out 30 CSV files.

       

      When I did it manually there are only 2 spreadsheets.

       

      Any ideas? I dont know anything about VBA code so not sure where to start.

       

      Thanks

      :)

      • Logaraj Sekar's avatar
        Logaraj Sekar
        Iron Contributor

        Hi Laura,

         

        Based on the RD reference, i created macro. So it will count no of RD references (without duplication).

         

        If RD reference count is 30, it will create 30 Sheets. In case you need change, explain it i will do changes in macro.

Resources