vSQL = "Select CC, Logon_Nome, Users_Nome_Completo as Nome_Completo, sum(paginas*simplex) as TotalSimplex, sum(paginas*TiposD_Duplex) as TotalDuplex from [ndd-completo] where (modeloIMP = " & Chr(34) & "T632" & Chr(34) & " OR modeloIMP = " & Chr(34) & "T634" & Chr(34) & ") and not(IP like " & Chr(34) & "10.184.0.156" & Chr(34) & ") group by logon_nome, Users_nome_completo, CC Order by CC"
vSQL = "Select CC, Logon_Nome, Users_Nome_Completo as Nome_Completo, sum(paginas*Mono*simplex) as MonoSimplex, sum(paginas*Mono*TiposD_Duplex) as MonoDuplex, sum(paginas*color*simplex) as ColorSimplex, sum(paginas*color*TiposD_Duplex) as ColorDuplex from [ndd-completo] group by logon_nome, Users_nome_completo, CC Order by CC"
Pergunta
Slins
Galeraaaa !!!! Me ajudem...Sou novo no Forum e novíssimo no VB ! hehe
Eu não consigo entender algumas partes e está dando um erro que eu não entendo o porque???
Tem também um tal de CDBL...que eu não sei para que serve !
Me ajudem....por favor !
Private Sub CommandButton1_Click()
Dim vCon As New ADODB.Connection
Dim vRS As New ADODB.Recordset
Dim vSQL As String
Dim vRow As Double
Dim vRowC As Double
Dim vVerS As String
Dim vVerN As Double
Dim vCC As String
vCon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.ThisWorkbook.Path & "7" & Format(Now(), "MM") & "\AC07" & Format(Now(), "MM") & ".mdb"
vCon.Open
'Preenche Por Equipamento
Plan1.Select
vRow = 6
vRowC = 57
vSQL = "Select SN, sum(paginas) as Total from [ndd-completo] group by SN"
Set vRS = vCon.Execute(vSQL)
While Not (vRS.EOF)
If (Plan1.Cells(vRow, 1) <> "ccm") Then
If vRS("SN") = Plan1.Cells(vRow, 5) Then
Plan1.Cells(vRow, 7) = vRS("Total") * Plan1.Cells(vRow, 7)
Plan1.Cells(vRow, 8) = vRS("Total") * Plan1.Cells(vRow, 8)
Plan1.Cells(vRow, 9) = vRS("Total") * Plan1.Cells(vRow, 9)
vRow = 6
vRS.MoveNext
Else
vRow = vRow + 1
End If
Else
Plan1.Cells(vRowC, 3) = vRS("SN")
Plan1.Cells(vRowC, 4) = vRS("Total")
vRowC = vRowC + 1
vRow = 6
vRS.MoveNext
End If
Wend
Set vRS = Nothing
vRow = 6
vSQL = "Select SERIAL_NUMBER, sum(Impression_Count) as Total from [mv-cwt-copias-senhas] group by SERIAL_NUMBER"
Set vRS = vCon.Execute(vSQL)
While (Plan1.Cells(vRow, 1) <> "ccm") And (Not (vRS.EOF))
If vRS("SERIAL_NUMBER") = Plan1.Cells(vRow, 5) Then
Plan1.Cells(vRow, 10) = Plan1.Cells(vRow, 10) + vRS("Total")
vRow = 6
vRS.MoveNext
Else
vRow = vRow + 1
End If
Wend
Set vRS = Nothing
'Preenche POR CC-USUARIO Lexmark
Plan7.Select
vRow = 12
vRowC = 11
vSQL = "Select CC, Logon_Nome, Users_Nome_Completo as Nome_Completo, sum(paginas*simplex) as TotalSimplex, sum(paginas*TiposD_Duplex) as TotalDuplex from [ndd-completo] where (modeloIMP = " & Chr(34) & "T632" & Chr(34) & " OR modeloIMP = " & Chr(34) & "T634" & Chr(34) & ") and not(IP like " & Chr(34) & "10.184.0.156" & Chr(34) & ") group by logon_nome, Users_nome_completo, CC Order by CC"
Set vRS = vCon.Execute(vSQL)
Plan7.Cells(vRowC, 2) = vRS("CC")
Plan7.Cells(vRowC, 4) = vRS("TotalSimplex")
Plan7.Cells(vRowC, 5) = vRS("TotalDuplex")
Plan7.Cells(vRowC, 7) = Plan7.Cells(vRowC, 4) + Plan7.Cells(vRowC, 5)
If IsNull(vRS("Nome_Completo")) Then
Plan7.Cells(vRow, 3) = vRS("Logon_Nome")
Else
Plan7.Cells(vRow, 3) = vRS("Nome_Completo")
End If
Plan7.Cells(vRow, 4) = vRS("TotalSimplex")
Plan7.Cells(vRow, 5) = vRS("TotalDuplex")
Plan7.Range("B" & vRowC & ":G" & vRowC).Interior.Color = RGB(0, 128, 0)
Plan7.Range("B" & vRowC & ":G" & vRowC).Font.Bold = True
Plan7.Range("B" & vRowC & ":G" & vRowC).Font.Color = vbWhite
Plan7.Range("C" & vRow & ":G" & vRow).Borders(xlEdgeBottom).LineStyle = xlContinuous
vRS.MoveNext
While Not (vRS.EOF)
If vRS("CC") = Plan7.Cells(vRowC, 2) Then
vRow = vRow + 1
If IsNull(vRS("Nome_Completo")) Then
Plan7.Cells(vRow, 3) = vRS("Logon_Nome")
Else
Plan7.Cells(vRow, 3) = vRS("Nome_Completo")
End If
Plan7.Cells(vRow, 4) = vRS("TotalSimplex")
Plan7.Cells(vRow, 5) = vRS("TotalDuplex")
Plan7.Cells(vRowC, 4) = Plan7.Cells(vRowC, 4) + vRS("TotalSimplex")
Plan7.Cells(vRowC, 5) = Plan7.Cells(vRowC, 5) + vRS("TotalDuplex")
Plan7.Cells(vRowC, 7) = Plan7.Cells(vRowC, 4) + Plan7.Cells(vRowC, 5)
Plan7.Range("C" & vRow & ":G" & vRow).Borders(xlEdgeBottom).LineStyle = xlContinuous
Else
vRowC = vRow + 1
vRow = vRowC + 1
Plan7.Cells(vRowC, 2) = vRS("CC")
Plan7.Cells(vRowC, 4) = vRS("TotalSimplex")
Plan7.Cells(vRowC, 5) = vRS("TotalDuplex")
Plan7.Cells(vRowC, 7) = Plan7.Cells(vRowC, 4) + Plan7.Cells(vRowC, 5)
If IsNull(vRS("Nome_Completo")) Then
Plan7.Cells(vRow, 3) = vRS("Logon_Nome")
Else
Plan7.Cells(vRow, 3) = vRS("Nome_Completo")
End If
Plan7.Cells(vRow, 4) = vRS("TotalSimplex")
Plan7.Cells(vRow, 5) = vRS("TotalDuplex")
Plan7.Range("B" & vRowC & ":G" & vRowC).Interior.Color = RGB(0, 128, 0)
Plan7.Range("B" & vRowC & ":G" & vRowC).Font.Bold = True
Plan7.Range("B" & vRowC & ":G" & vRowC).Font.Color = vbWhite
Plan7.Range("C" & vRow & ":G" & vRow).Borders(xlEdgeBottom).LineStyle = xlContinuous
End If
vRS.MoveNext
Wend
Set vRS = Nothing
vRowC = 11
vSQL = "Select cc, sum(impression_count) as Total from [mv-cwt-copias-senhas] group by cc"
Set vRS = vCon.Execute(vSQL)
While Not (vRS.EOF) And (vRowC <= (vRow + 1))
---------------------------------Não consigo entender nada desde aqui...até um pouco abaixo a linha que dá erro.....----------
If (Plan7.Cells(vRowC, 2) <> "") And (vRS("cc") <> "Rateio") Then
vVerS = Left(Plan7.Cells(vRowC, 2), 7)
vVerN = CDbl(vVerS)
vCC = CDbl(Left(vRS("cc"), 7))
Else
vVerN = 0
End If
If (Plan7.Cells(vRowC, 2) <> "") And (vVerN <= vCC) Then ---------- Erro aparece aqui...como tipos incompativeis....erro 13
If InStr(Plan7.Cells(vRowC, 2), vRS("cc")) > 0 Then
Plan7.Cells(vRowC, 6) = vRS("Total")
Plan7.Cells(vRowC, 7) = Plan7.Cells(vRowC, 7) + vRS("Total")
vRowC = 11
vRS.MoveNext
Else
vRowC = vRowC + 1
End If
Else
If Plan7.Cells(vRowC, 2) = "" Then
vRowC = vRowC + 1
Else
Plan7.Rows(vRowC).Insert
Plan7.Cells(vRowC, 2) = vRS("cc")
Plan7.Cells(vRowC, 4) = 0
Plan7.Cells(vRowC, 5) = 0
Plan7.Cells(vRowC, 6) = vRS("Total")
Plan7.Cells(vRowC, 7) = vRS("Total")
Plan7.Range("B" & vRowC & ":G" & vRowC).Interior.Color = RGB(0, 128, 0)
Plan7.Range("B" & vRowC & ":G" & vRowC).Font.Bold = True
Plan7.Range("B" & vRowC & ":G" & vRowC).Font.Color = vbWhite
vRowC = 11
vRow = vRow + 1
vRS.MoveNext
End If
End If
Wend
Set vRS = Nothing
'Preenche POR CC-USUARIO
Plan2.Select
vRowC = 11
vRow = 12
vSQL = "Select CC, Logon_Nome, Users_Nome_Completo as Nome_Completo, sum(paginas*Mono*simplex) as MonoSimplex, sum(paginas*Mono*TiposD_Duplex) as MonoDuplex, sum(paginas*color*simplex) as ColorSimplex, sum(paginas*color*TiposD_Duplex) as ColorDuplex from [ndd-completo] group by logon_nome, Users_nome_completo, CC Order by CC"
Set vRS = vCon.Execute(vSQL)
Plan2.Cells(vRowC, 2) = vRS("CC")
Plan2.Cells(vRowC, 4) = vRS("MonoSimplex")
Plan2.Cells(vRowC, 5) = vRS("MonoDuplex")
Plan2.Cells(vRowC, 6) = vRS("ColorSimplex")
Plan2.Cells(vRowC, 7) = vRS("ColorDuplex")
Plan2.Cells(vRowC, 9) = Plan2.Cells(vRowC, 4) + Plan2.Cells(vRowC, 5) + Plan2.Cells(vRowC, 6) + Plan2.Cells(vRowC, 7)
If IsNull(vRS("Nome_Completo")) Then
Plan2.Cells(vRow, 3) = vRS("Logon_Nome")
Else
Plan2.Cells(vRow, 3) = vRS("Nome_Completo")
End If
Plan2.Cells(vRow, 4) = vRS("MonoSimplex")
Plan2.Cells(vRow, 5) = vRS("MonoDuplex")
Plan2.Cells(vRow, 6) = vRS("ColorSimplex")
Plan2.Cells(vRow, 7) = vRS("ColorDuplex")
Plan2.Range("B" & vRowC & ":I" & vRowC).Interior.Color = RGB(0, 128, 0)
Plan2.Range("B" & vRowC & ":I" & vRowC).Font.Bold = True
Plan2.Range("B" & vRowC & ":I" & vRowC).Font.Color = vbWhite
Plan2.Range("C" & vRow & ":I" & vRow).Borders(xlEdgeBottom).LineStyle = xlContinuous
vRS.MoveNext
While Not (vRS.EOF)
If vRS("CC") = Plan2.Cells(vRowC, 2) Then
vRow = vRow + 1
If IsNull(vRS("Nome_Completo")) Then
Plan2.Cells(vRow, 3) = vRS("Logon_Nome")
Else
Plan2.Cells(vRow, 3) = vRS("Nome_Completo")
End If
Plan2.Cells(vRow, 4) = vRS("MonoSimplex")
Plan2.Cells(vRow, 5) = vRS("MonoDuplex")
Plan2.Cells(vRow, 6) = vRS("ColorSimplex")
Plan2.Cells(vRow, 7) = vRS("ColorDuplex")
Plan2.Cells(vRowC, 4) = Plan2.Cells(vRowC, 4) + vRS("MonoSimplex")
Plan2.Cells(vRowC, 5) = Plan2.Cells(vRowC, 5) + vRS("MonoDuplex")
Plan2.Cells(vRowC, 6) = Plan2.Cells(vRowC, 6) + vRS("ColorSimplex")
Plan2.Cells(vRowC, 7) = Plan2.Cells(vRowC, 7) + vRS("ColorDuplex")
Plan2.Cells(vRowC, 9) = Plan2.Cells(vRowC, 4) + Plan2.Cells(vRowC, 5) + Plan2.Cells(vRowC, 6) + Plan2.Cells(vRowC, 7)
Plan2.Range("C" & vRow & ":I" & vRow).Borders(xlEdgeBottom).LineStyle = xlContinuous
Else
vRowC = vRow + 1
vRow = vRowC + 1
Plan2.Cells(vRowC, 2) = vRS("CC")
Plan2.Cells(vRowC, 4) = vRS("MonoSimplex")
Plan2.Cells(vRowC, 5) = vRS("MonoDuplex")
Plan2.Cells(vRowC, 6) = vRS("ColorSimplex")
Plan2.Cells(vRowC, 7) = vRS("ColorDuplex")
Plan2.Cells(vRowC, 9) = Plan2.Cells(vRowC, 4) + Plan2.Cells(vRowC, 5) + Plan2.Cells(vRowC, 6) + Plan2.Cells(vRowC, 7)
If IsNull(vRS("Nome_Completo")) Then
Plan2.Cells(vRow, 3) = vRS("Logon_Nome")
Else
Plan2.Cells(vRow, 3) = vRS("Nome_Completo")
End If
Plan2.Cells(vRow, 4) = vRS("MonoSimplex")
Plan2.Cells(vRow, 5) = vRS("MonoDuplex")
Plan2.Cells(vRow, 6) = vRS("ColorSimplex")
Plan2.Cells(vRow, 7) = vRS("ColorDuplex")
Plan2.Range("B" & vRowC & ":I" & vRowC).Interior.Color = RGB(0, 128, 0)
Plan2.Range("B" & vRowC & ":I" & vRowC).Font.Bold = True
Plan2.Range("B" & vRowC & ":I" & vRowC).Font.Color = vbWhite
Plan2.Range("C" & vRow & ":I" & vRow).Borders(xlEdgeBottom).LineStyle = xlContinuous
End If
vRS.MoveNext
Wend
Set vRS = Nothing
vRowC = 11
vSQL = "Select cc, sum(impression_count) as Total from [mv-cwt-copias-senhas] group by cc"
Set vRS = vCon.Execute(vSQL)
While Not (vRS.EOF) And (vRowC <= (vRow + 1))
If (Plan2.Cells(vRowC, 2) <> "") And (vRS("cc") <> "Rateio") Then
vVerS = Left(Plan2.Cells(vRowC, 2), 7) ------------------------------------ Não entendo esta linha !
vVerN = CDbl(vVerS) ------------------------------------------------------------ Não sei para que serve CDBL?
vCC = CDbl(Left(vRS("cc"), 7)) ------------------------------------------------- Também não entendo esta !
Else
vVerN = 0
End If
If (Plan2.Cells(vRowC, 2) <> "") And (vVerN <= vCC) Then ----------------erro aparece nesta linha !
If InStr(Plan2.Cells(vRowC, 2), vRS("cc")) > 0 Then
Plan2.Cells(vRowC, 8) = vRS("Total")
Plan2.Cells(vRowC, 9) = Plan2.Cells(vRowC, 9) + vRS("Total")
vRowC = 11
vRS.MoveNext
Else
vRowC = vRowC + 1
End If
Else
If Plan2.Cells(vRowC, 2) = "" Then
vRowC = vRowC + 1
Else
Plan2.Rows(vRowC).Insert
Plan2.Cells(vRowC, 2) = vRS("cc")
Plan2.Cells(vRowC, 4) = 0
Plan2.Cells(vRowC, 5) = 0
Plan2.Cells(vRowC, 6) = 0
Plan2.Cells(vRowC, 7) = 0
Plan2.Cells(vRowC, 8) = vRS("Total")
Plan2.Cells(vRowC, 9) = vRS("Total")
Plan2.Range("B" & vRowC & ":I" & vRowC).Interior.Color = RGB(0, 128, 0)
Plan2.Range("B" & vRowC & ":I" & vRowC).Font.Bold = True
Plan2.Range("B" & vRowC & ":I" & vRowC).Font.Color = vbWhite
vRowC = 11
vRow = vRow + 1
vRS.MoveNext
End If
End If
Wend
Set vRS = Nothing
'Preenche Lexmark
Plan3.Select
vRow = 6
vSQL = "Select SERIAL_NUMBER, sum(Impression_Count) as Total from [mv-cwt-copias-senhas] group by SERIAL_NUMBER"
Set vRS = vCon.Execute(vSQL)
While (Not (vRS.EOF)) And (vRow < 20)
If vRS("SERIAL_NUMBER") = Plan3.Cells(vRow, 4) Then
Plan3.Cells(vRow, 7) = Plan3.Cells(vRow, 7) + vRS("Total")
vRow = 6
vRS.MoveNext
Else
vRow = vRow + 1
End If
Wend
Set vRS = Nothing
vSQL = "Select SN, sum(paginas) as Total from [ndd-completo] where modeloIMP = " & Chr(34) & "T632" & Chr(34) & " OR modeloIMP = " & Chr(34) & "T634" & Chr(34) & " group by SN"
Set vRS = vCon.Execute(vSQL)
While (Not (vRS.EOF)) And (vRow < 20)
If vRS("SN") = Plan3.Cells(vRow, 4) Then
Plan3.Cells(vRow, 6) = Plan3.Cells(vRow, 6) + vRS("Total")
vRow = 6
vRS.MoveNext
Else
If Plan3.Cells(vRow, 6) = "" Then
vRow = 6
vRS.MoveNext
Else
vRow = vRow + 1
End If
End If
Wend
Set vRS = Nothing
vCon.Close
Application.ThisWorkbook.SaveAs Application.ThisWorkbook.Path & "7" & Format(Now(), "MM") & "\Enviar\Relatorio CWT " & Format(Now() - 20, "mmmm") & ".xls"
End Sub
Editado por SlinsLink para o comentário
Compartilhar em outros sites
3 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.