Move Data from a Mastersheet to Multiple Sheets based on Unique Code and arranging the output sheets [closed]











up vote
-1
down vote

favorite












I have the following code which moves data from a mastersheet to different sheets after grouping them with a unique code in the first column. I need to arrange the output in a specific order by referencing another excel(output sheets to be ordered as per the column values in the excel to be referred). Can anyone help.



Sub parse_data()

Dim lr As Long
Dim ws As Worksheet
Dim vcol, i As Integer
Dim icol As Long
Dim myarr As Variant
Dim title As String
Dim titlerow As Integer
vcol = 1
Set ws = Sheets("Test Data1")
lr = ws.Cells(ws.Rows.Count, vcol).End(xlUp).Row
title = "A1:J1"
titlerow = ws.Range(title).Cells(1).Row
icol = ws.Columns.Count
ws.Cells(1, icol) = "Unique"
For i = 2 To lr
On Error Resume Next
If ws.Cells(i, vcol) <> "" And Application.WorksheetFunction.Match(ws.Cells(i, vcol), ws.Columns(icol), 0) = 0 Then
ws.Cells(ws.Rows.Count, icol).End(xlUp).Offset(1) = ws.Cells(i, vcol)
End If
Next
myarr = Application.WorksheetFunction.Transpose(ws.Columns(icol).SpecialCells(xlCellTypeConstants))
ws.Columns(icol).Clear
For i = 2 To UBound(myarr)
ws.Range(title).AutoFilter field:=vcol, Criteria1:=myarr(i) & ""
If Not Evaluate("=ISREF('" & myarr(i) & "'!A1)") Then
Sheets.Add(After:=Worksheets(Worksheets.Count)).Name = "BR" & myarr(i) & ""
Else
Sheets(myarr(i) & "").Move After:=Worksheets(Worksheets.Count)
End If
ws.Range("A" & titlerow & ":A" & lr).EntireRow.Copy Sheets(myarr(i) & "").Range("A1")
Sheets(myarr(i) & "").Columns.AutoFit
Next
ws.AutoFilterMode = False
ws.Activate
End Sub









share|improve this question















closed as off-topic by πάντα ῥεῖ, 200_success, Sᴀᴍ Onᴇᴌᴀ, Toby Speight, Graipher Nov 27 at 18:17


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, 200_success, Sᴀᴍ Onᴇᴌᴀ, Toby Speight, Graipher

If this question can be reworded to fit the rules in the help center, please edit the question.

















    up vote
    -1
    down vote

    favorite












    I have the following code which moves data from a mastersheet to different sheets after grouping them with a unique code in the first column. I need to arrange the output in a specific order by referencing another excel(output sheets to be ordered as per the column values in the excel to be referred). Can anyone help.



    Sub parse_data()

    Dim lr As Long
    Dim ws As Worksheet
    Dim vcol, i As Integer
    Dim icol As Long
    Dim myarr As Variant
    Dim title As String
    Dim titlerow As Integer
    vcol = 1
    Set ws = Sheets("Test Data1")
    lr = ws.Cells(ws.Rows.Count, vcol).End(xlUp).Row
    title = "A1:J1"
    titlerow = ws.Range(title).Cells(1).Row
    icol = ws.Columns.Count
    ws.Cells(1, icol) = "Unique"
    For i = 2 To lr
    On Error Resume Next
    If ws.Cells(i, vcol) <> "" And Application.WorksheetFunction.Match(ws.Cells(i, vcol), ws.Columns(icol), 0) = 0 Then
    ws.Cells(ws.Rows.Count, icol).End(xlUp).Offset(1) = ws.Cells(i, vcol)
    End If
    Next
    myarr = Application.WorksheetFunction.Transpose(ws.Columns(icol).SpecialCells(xlCellTypeConstants))
    ws.Columns(icol).Clear
    For i = 2 To UBound(myarr)
    ws.Range(title).AutoFilter field:=vcol, Criteria1:=myarr(i) & ""
    If Not Evaluate("=ISREF('" & myarr(i) & "'!A1)") Then
    Sheets.Add(After:=Worksheets(Worksheets.Count)).Name = "BR" & myarr(i) & ""
    Else
    Sheets(myarr(i) & "").Move After:=Worksheets(Worksheets.Count)
    End If
    ws.Range("A" & titlerow & ":A" & lr).EntireRow.Copy Sheets(myarr(i) & "").Range("A1")
    Sheets(myarr(i) & "").Columns.AutoFit
    Next
    ws.AutoFilterMode = False
    ws.Activate
    End Sub









    share|improve this question















    closed as off-topic by πάντα ῥεῖ, 200_success, Sᴀᴍ Onᴇᴌᴀ, Toby Speight, Graipher Nov 27 at 18:17


    This question appears to be off-topic. The users who voted to close gave this specific reason:


    • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, 200_success, Sᴀᴍ Onᴇᴌᴀ, Toby Speight, Graipher

    If this question can be reworded to fit the rules in the help center, please edit the question.















      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      I have the following code which moves data from a mastersheet to different sheets after grouping them with a unique code in the first column. I need to arrange the output in a specific order by referencing another excel(output sheets to be ordered as per the column values in the excel to be referred). Can anyone help.



      Sub parse_data()

      Dim lr As Long
      Dim ws As Worksheet
      Dim vcol, i As Integer
      Dim icol As Long
      Dim myarr As Variant
      Dim title As String
      Dim titlerow As Integer
      vcol = 1
      Set ws = Sheets("Test Data1")
      lr = ws.Cells(ws.Rows.Count, vcol).End(xlUp).Row
      title = "A1:J1"
      titlerow = ws.Range(title).Cells(1).Row
      icol = ws.Columns.Count
      ws.Cells(1, icol) = "Unique"
      For i = 2 To lr
      On Error Resume Next
      If ws.Cells(i, vcol) <> "" And Application.WorksheetFunction.Match(ws.Cells(i, vcol), ws.Columns(icol), 0) = 0 Then
      ws.Cells(ws.Rows.Count, icol).End(xlUp).Offset(1) = ws.Cells(i, vcol)
      End If
      Next
      myarr = Application.WorksheetFunction.Transpose(ws.Columns(icol).SpecialCells(xlCellTypeConstants))
      ws.Columns(icol).Clear
      For i = 2 To UBound(myarr)
      ws.Range(title).AutoFilter field:=vcol, Criteria1:=myarr(i) & ""
      If Not Evaluate("=ISREF('" & myarr(i) & "'!A1)") Then
      Sheets.Add(After:=Worksheets(Worksheets.Count)).Name = "BR" & myarr(i) & ""
      Else
      Sheets(myarr(i) & "").Move After:=Worksheets(Worksheets.Count)
      End If
      ws.Range("A" & titlerow & ":A" & lr).EntireRow.Copy Sheets(myarr(i) & "").Range("A1")
      Sheets(myarr(i) & "").Columns.AutoFit
      Next
      ws.AutoFilterMode = False
      ws.Activate
      End Sub









      share|improve this question















      I have the following code which moves data from a mastersheet to different sheets after grouping them with a unique code in the first column. I need to arrange the output in a specific order by referencing another excel(output sheets to be ordered as per the column values in the excel to be referred). Can anyone help.



      Sub parse_data()

      Dim lr As Long
      Dim ws As Worksheet
      Dim vcol, i As Integer
      Dim icol As Long
      Dim myarr As Variant
      Dim title As String
      Dim titlerow As Integer
      vcol = 1
      Set ws = Sheets("Test Data1")
      lr = ws.Cells(ws.Rows.Count, vcol).End(xlUp).Row
      title = "A1:J1"
      titlerow = ws.Range(title).Cells(1).Row
      icol = ws.Columns.Count
      ws.Cells(1, icol) = "Unique"
      For i = 2 To lr
      On Error Resume Next
      If ws.Cells(i, vcol) <> "" And Application.WorksheetFunction.Match(ws.Cells(i, vcol), ws.Columns(icol), 0) = 0 Then
      ws.Cells(ws.Rows.Count, icol).End(xlUp).Offset(1) = ws.Cells(i, vcol)
      End If
      Next
      myarr = Application.WorksheetFunction.Transpose(ws.Columns(icol).SpecialCells(xlCellTypeConstants))
      ws.Columns(icol).Clear
      For i = 2 To UBound(myarr)
      ws.Range(title).AutoFilter field:=vcol, Criteria1:=myarr(i) & ""
      If Not Evaluate("=ISREF('" & myarr(i) & "'!A1)") Then
      Sheets.Add(After:=Worksheets(Worksheets.Count)).Name = "BR" & myarr(i) & ""
      Else
      Sheets(myarr(i) & "").Move After:=Worksheets(Worksheets.Count)
      End If
      ws.Range("A" & titlerow & ":A" & lr).EntireRow.Copy Sheets(myarr(i) & "").Range("A1")
      Sheets(myarr(i) & "").Columns.AutoFit
      Next
      ws.AutoFilterMode = False
      ws.Activate
      End Sub






      vba excel macros






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 27 at 18:12

























      asked Nov 27 at 17:45









      Aarohi

      11




      11




      closed as off-topic by πάντα ῥεῖ, 200_success, Sᴀᴍ Onᴇᴌᴀ, Toby Speight, Graipher Nov 27 at 18:17


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, 200_success, Sᴀᴍ Onᴇᴌᴀ, Toby Speight, Graipher

      If this question can be reworded to fit the rules in the help center, please edit the question.




      closed as off-topic by πάντα ῥεῖ, 200_success, Sᴀᴍ Onᴇᴌᴀ, Toby Speight, Graipher Nov 27 at 18:17


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, 200_success, Sᴀᴍ Onᴇᴌᴀ, Toby Speight, Graipher

      If this question can be reworded to fit the rules in the help center, please edit the question.



























          active

          oldest

          votes






















          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes

          Popular posts from this blog

          Terni

          A new problem with tex4ht and tikz

          Sun Ra