Notifications
Clear all

Separar Dados de planilha em novos arquivos

6 Posts
2 Usuários
0 Reactions
1,313 Visualizações
(@miguexcel)
Posts: 167
Reputable Member
Topic starter
 

Olá,

Tenho um problema que preciso resolver mas estou tendo dificuldade. TEnho uma planilha com dados e preciso separar esses dados por idade e criar/salvar um arquivo por cada grupo de idade. Alguém sabe como posso fazer? Já vi alguns tópicos no site, mas não consigo baixar os arquivos de exemplo nem perceber as soluções.

Alguém me pode ajudar?

Miguexcel, você já é membro do Forum desde 2012, então deve ser conhecedor das regras, por isto deletei o arquivo por não estar compactado.
Compacte o mesmo e anexe novamente.

Nossas Regras : viewtopic.php?f=7&t=203
• Upload
Devido a ultrapassagem da marca de 1,5Gb de armazenamento de arquivos na hospedagem do Planilhando,
limitaremos o tamanho de cada arquivo para 2Mb sendo obrigatório o uso dos formatos .zip - .rar - .ice visto
a gratuidade e não geração de recursos para bancar o site.

 
Postado : 14/05/2015 2:54 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Bom dia!!

Visto que seu arquivo modelo e compactado, não está disponível ....

Tente adaptar...

Option Explicit

Sub ParseItems()
'Jerry Beaucaire  (4/22/2010)
'Based on selected column, data is filtered to individual workbooks
'workbooks are named for the value plus today's date
Dim LR As Long, Itm As Long, MyCount As Long, vCol As Long
Dim ws As Worksheet, MyArr As Variant, vTitles As String, SvPath As String

'Sheet with data in it
   Set ws = Sheets("Original Data")

'Path to save files into, remember the final 
    SvPath = "C:2010"

'Range where titles are across top of data, as string, data MUST
'have titles in this row, edit to suit your titles locale
    vTitles = "A1:Z1"
   
'Choose column to evaluate from, column A = 1, B = 2, etc.
   vCol = Application.InputBox("What column to split data by? " & vbLf _
        & vbLf & "(A=1, B=2, C=3, etc)", "Which column?", 1, Type:=1)
   If vCol = 0 Then Exit Sub

'Spot bottom row of data
   LR = ws.Cells(ws.Rows.Count, vCol).End(xlUp).Row

'Speed up macro execution
   Application.ScreenUpdating = False

'Get a temporary list of unique values from key column
    ws.Columns(vCol).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=ws.Range("EE1"), Unique:=True

'Sort the temporary list
    ws.Columns("EE:EE").Sort Key1:=ws.Range("EE2"), Order1:=xlAscending, Header:=xlYes, _
       OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal

'Put list into an array for looping (values cannot be the result of formulas, must be constants)
    MyArr = Application.WorksheetFunction.Transpose(ws.Range("EE2:EE" & Rows.Count).SpecialCells(xlCellTypeConstants))

'clear temporary worksheet list
    ws.Range("EE:EE").Clear

'Turn on the autofilter, one column only is all that is needed
    ws.Range(vTitles).AutoFilter

'Loop through list one value at a time
    For Itm = 1 To UBound(MyArr)
        ws.Range(vTitles).AutoFilter Field:=vCol, Criteria1:=MyArr(Itm)
        
        ws.Range("A1:A" & LR).EntireRow.Copy
        Workbooks.Add
        Range("A1").PasteSpecial xlPasteAll
        Cells.Columns.AutoFit
        MyCount = MyCount + Range("A" & Rows.Count).End(xlUp).Row - 1
        
        ActiveWorkbook.SaveAs SvPath & MyArr(Itm) & Format(Date, " MM-DD-YY"), xlNormal
        'ActiveWorkbook.SaveAs SvPath & MyArr(Itm) & Format(Date, " MM-DD-YY") & ".xlsx", 51   'use for Excel 2007+
        ActiveWorkbook.Close False
        
        ws.Range(vTitles).AutoFilter Field:=vCol
    Next Itm

'Cleanup
    ws.AutoFilterMode = False
    MsgBox "Rows with data: " & (LR - 1) & vbLf & "Rows copied to other sheets: " & MyCount & vbLf & "Hope they match!!"
    Application.ScreenUpdating = True
End Sub

Att

 
Postado : 14/05/2015 7:08 am
(@miguexcel)
Posts: 167
Reputable Member
Topic starter
 

Alex,

Envio arquivo novamente. Não estou conseguindo adaptar

 
Postado : 14/05/2015 7:14 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Bom dia!!

Altere essas linhas conforme sua necessidade

   Set ws = Sheets("AleVBA_Guia") 'O nome da guia que contém os dados

    SvPath = "C:UsersalexandreVBADownloads" 'Local onde vai salvar

Att

 
Postado : 14/05/2015 7:41 am
(@miguexcel)
Posts: 167
Reputable Member
Topic starter
 

Alex,

Está perfeito. Só tem uma dúvida. Existe forma de fazer isto para arquivos externos? OU seja, deixo a macro num arquivo isolado, em que abre os diferentes arquivos com informação e faz esse trabalho...?

 
Postado : 14/05/2015 8:12 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa tarde!!

Por favor, click na mãozinha!!

Sua pergunta não condiz com sua postagem original, mas respondendo sua pergunta, se eu entendi bem, sim é possível.

Existe forma de fazer isto para arquivos externos? OU seja, deixo a macro num arquivo isolado, em que abre os diferentes arquivos com informação e faz esse trabalho...?

Att

 
Postado : 14/05/2015 9:56 am