Ajuda com tabulação de Dados

AndersonDorneles

21-02-2018 19:05:18

Olá,

Estou montando um relatório, pegando dados de uma planilha (foto anexa 1) e colocando em outra (foto anexa 2), da qual vou salvar em PDF. Esta tudo funcionando perfeitamente, porem não estou conseguindo tabular os dados.

código:

Código: Selecionar todos

Private Sub FRS_Enviar_Oficio_OK_Click()

    Dim lastRow As Long
    Dim Verifica As String
    Dim i As Integer
    Dim Compara_Valor As String
    Dim MAIOR As Integer
    Dim Myr As Range
    Dim IMEI As String
    Dim IMEI_2 As String
    Dim Descricao As String
    Dim Data_BO As Date
    Dim Data_Fato_BO As Date
    Dim BO As String
    Dim Delegacia As String
    Dim Regional As String
    Dim Nome_Completo As String

    
    Sheets("Configuracoes").Select
    Delegacia = Sheets("Configuracoes").Cells(2, 2).Value
    Regional = Sheets("Configuracoes").Cells(2, 3).Value
    Nome_Completo = Delegacia + " - " + Regional
    Nome_Completo = Sheets("Anexo_FRS").Cells(1, 2).Value
    
    Sheets("Furto_Roubo_Smarfones").Select
    lastRow = Sheets("Furto_Roubo_Smarfones").Range("A1:M1500").End(xlDown).Row
    Verifica = Sheets("Furto_Roubo_Smarfones").Cells(2, 2).Value
    
    Set Myr = Worksheets("Anexo_FRS").Range("A2:A65000")
    MAIOR = Application.WorksheetFunction.Max(Myr)

'----------------------------------------------------------------------------------------------------------------------------------'
If Verifica <> "" Then
'----------------------------------------------------------------------------------------------------------------------------------'


Sheets("Anexo_FRS").Cells(1, 6).Value = "Ofício n.º :"
Sheets("Anexo_FRS").Cells(1, 7).Value = Me.FRS_OFICIO.Value

    For i = 2 To lastRow
        
           Compara_Valor = Sheets("Furto_Roubo_Smarfones").Cells(i, 6).Value
           
          If Compara_Valor = "NÃO" Then

            '--------------------- pega os valores da planilha original ------------------------'
            Descricao = Sheets("Furto_Roubo_Smarfones").Cells(i, 3).Value
            IMEI = Sheets("Furto_Roubo_Smarfones").Cells(i, 4).Value
            IMEI_2 = Sheets("Furto_Roubo_Smarfones").Cells(i, 5).Value
            BO = Sheets("Furto_Roubo_Smarfones").Cells(i, 10).Value
            Data_BO = Sheets("Furto_Roubo_Smarfones").Cells(i, 11).Value
            Data_Fato_BO = Sheets("Furto_Roubo_Smarfones").Cells(i, 12).Value
            '-----------------------------------------------------------------------------------'
            '------------------- coloca na planilha de relatório -------------------------------'
                Sheets("Anexo_FRS").Cells(i + 1, 1).Value = MAIOR + 1
                Sheets("Anexo_FRS").Cells(i + 1, 2).Value = Descricao
                Sheets("Anexo_FRS").Cells(i + 1, 3).Value = IMEI
                Sheets("Anexo_FRS").Cells(i + 1, 4).Value = IMEI_2
                Sheets("Anexo_FRS").Cells(i + 1, 5).Value = BO
                Sheets("Anexo_FRS").Cells(i + 1, 6).Value = Format(Data_BO, "dd/mm/yyyy")
                Sheets("Anexo_FRS").Cells(i + 1, 7).Value = Format(Data_Fato_BO, "dd/mm/yyyy")
            '-----------------------------------------------------------------------------------'
                End If
       
    Next i
   
Else
MsgBox "Planilha Vazia"
End If

End Sub

Os dados a serem transferidos de uma planilha a outra, são somente os que na coluna "F" (Imagem Anexa 1) estiver com "NÃO". O problema esta na montagem desses dados na outra planilha (Imagem Anexa 2).

Se alguem puder ajudar.

Att,

Anderson Silva Dorneles

srobles

10-03-2018 04:43:53

Anderson,

Sem acesso ao arquivo para testes fica difícil, então vou chutar uma possibilidade :

Código: Selecionar todos

Private Sub FRS_Enviar_Oficio_OK_Click()

    Dim lastRow As Long
    Dim Verifica As String
    Dim i As Integer
    Dim Compara_Valor As String
    Dim MAIOR As Integer
    Dim Myr As Range
    Dim IMEI As String
    Dim IMEI_2 As String
    Dim Descricao As String
    Dim Data_BO As Date
    Dim Data_Fato_BO As Date
    Dim BO As String
    Dim Delegacia As String
    Dim Regional As String
    Dim Nome_Completo As String

    
    Sheets("Configuracoes").Select
    Delegacia = Sheets("Configuracoes").Cells(2, 2).Value
    Regional = Sheets("Configuracoes").Cells(2, 3).Value
    Nome_Completo = Delegacia + " - " + Regional
    Nome_Completo = Sheets("Anexo_FRS").Cells(1, 2).Value
    
    Sheets("Furto_Roubo_Smarfones").Select
    lastRow = Sheets("Furto_Roubo_Smarfones").Cells(Sheets("Furto_Roubo_Smarfones").Rows.Count, 1).End(xlUp).Row
    Verifica = Sheets("Furto_Roubo_Smarfones").Cells(2, 2).Value
    
    Set Myr = Worksheets("Anexo_FRS").Range("A2:A65000")
    MAIOR = Application.WorksheetFunction.Max(Myr)

'----------------------------------------------------------------------------------------------------------------------------------'
If Verifica <> "" Then
'----------------------------------------------------------------------------------------------------------------------------------'


Sheets("Anexo_FRS").Cells(1, 6).Value = "Ofício n.º :"
Sheets("Anexo_FRS").Cells(1, 7).Value = Me.FRS_OFICIO.Value

    For i = 2 To lastRow
        
           Compara_Valor = Sheets("Furto_Roubo_Smarfones").Cells(i, 6).Value
           
          If Compara_Valor = "NÃO" Then
          
          Dim novaLinha As Long
          
          novaLinha = Sheets("Anexo_FRS").Cells(Sheets("Anexo_FRS").Rows.Count, 1).End(xlUp).Row

            '--------------------- pega os valores da planilha original ------------------------'
            Descricao = Sheets("Furto_Roubo_Smarfones").Cells(i, 3).Value
            IMEI = Sheets("Furto_Roubo_Smarfones").Cells(i, 4).Value
            IMEI_2 = Sheets("Furto_Roubo_Smarfones").Cells(i, 5).Value
            BO = Sheets("Furto_Roubo_Smarfones").Cells(i, 10).Value
            Data_BO = Sheets("Furto_Roubo_Smarfones").Cells(i, 11).Value
            Data_Fato_BO = Sheets("Furto_Roubo_Smarfones").Cells(i, 12).Value
            '-----------------------------------------------------------------------------------'
            '------------------- coloca na planilha de relatório -------------------------------'
                Sheets("Anexo_FRS").Cells(novaLinha, 1).Value = MAIOR + 1
                Sheets("Anexo_FRS").Cells(novaLinha, 2).Value = Descricao
                Sheets("Anexo_FRS").Cells(novaLinha, 3).Value = IMEI
                Sheets("Anexo_FRS").Cells(novaLinha, 4).Value = IMEI_2
                Sheets("Anexo_FRS").Cells(novaLinha, 5).Value = BO
                Sheets("Anexo_FRS").Cells(novaLinha, 6).Value = Format(Data_BO, "dd/mm/yyyy")
                Sheets("Anexo_FRS").Cells(novaLinha, 7).Value = Format(Data_Fato_BO, "dd/mm/yyyy")
            '-----------------------------------------------------------------------------------'
            
        End If
       
    Next i
   
Else
MsgBox "Planilha Vazia"
End If

End Sub
Abs