Vídeo recomendado
https://youtu.be/diWPPPhW-9E

VBA - Se o relatório estiver vazio, quero uma mensagem dizendo que nao ha nada nesse intervalo.

Fórum para dúvidas sobre os fundamentos da linguagem de programação Visual Basic no contexto do VBA
Zeca1456
Acabou de chegar
Acabou de chegar
Mensagens: 7
Registrado em: Seg Jul 30, 2018 4:18 pm

VBA - Se o relatório estiver vazio, quero uma mensagem dizendo que nao ha nada nesse intervalo.

Mensagem por Zeca1456 »

Ola pessoal.
Tenho essa macro:

Dim Dates As Date
Dim StartDate As Date
Dim EndDate As Date
Dim line As Long
Dim linelist As Long
Dim li As ListItem

line = 2

listvBetweenDates.ListItems.Clear

With Sheet1

While .Cells(line, 1).Value <> " "

Dates = .Cells(line, 16).Value

If Dates >= txtReportDateStart And Dates <= txtReportEndDate Then
If IsNumeric(.Cells(line, 23)) Then
End If
End If
End Sub
Funciona perfeitamente, só que preciso avisar o usuário quando não há nada no intervalo pesquisado.
Também preciso: Ao abrir; a planilha seja atualizada. No momento tem acontecido o seguinte Campo "Status" Hoje dia 30 de julho - mostra que está em atraso 10 dias, Amanhã quando abro o upDate não é feito.
Muito obrigado a todos.


Disable adblock

This site is supported by ads and donations.
If you see this text you are blocking our ads.
Please consider a Donation to support the site.


Avatar do usuário
Reinaldo
Jedi
Jedi
Mensagens: 1537
Registrado em: Sex Ago 01, 2014 4:09 pm
Localização: Garça - SP / SCS - SP

Re: VBA - Se o relatório estiver vazio, quero uma mensagem dizendo que nao ha nada nesse intervalo.

Mensagem por Reinaldo »

Não me leve a mal, mas assim nem com adivinhação.
O trecho da rotina nada faz alem de limpar o conteúdo de uma list, e verifica na linha dois coluna 23 da sheet1 se o valor e numero; nada mais e executado,como pode funcionar?

"Ao abrir; a planilha seja atualizada." verifique se a planilha estão com calculo automatico, se não estiver altere


Zeca1456
Acabou de chegar
Acabou de chegar
Mensagens: 7
Registrado em: Seg Jul 30, 2018 4:18 pm

Re: VBA - Se o relatório estiver vazio, quero uma mensagem dizendo que nao ha nada nesse intervalo.

Mensagem por Zeca1456 »

Eu só coloquei o trecho onde quero acrescentar um MsgBox. Entao quando isso ocorre--> If Dates >= txtReportDateStart And Dates <= txtReportEndDate Then
If IsNumeric(.Cells(line, 23)) Then
End If
End If
xxxxxxxxxxxxxxx ABAIXO CODIGO COMPLETO xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Private Sub btnFilterDates_Click() 'Botao Delayed
listvBetweenDates.ListItems.Clear 'Limpando a ListView Reports

lblTotalRecord = ""
lblTotal = ""


Sheet2.Range("A4:J30000").Clear
Sheet2.Range("A1").Clear
Sheet2.Range("E2") = ""
Sheet2.Range("E1") = ""
Sheet2.Range("H2") = ""



Dim Dates As Date
Dim StartDate As Date
Dim EndDate As Date
Dim line As Long
Dim linelist As Long
Dim li As ListItem



line = 2 'Porque 2? Por que a primeira line na minha planilha contendo dados é a line 2. Estamos referindo a Sheet1."Clients"

listvBetweenDates.ListItems.Clear



With Sheet1

While .Cells(line, 1).Value <> "" 'Onde line é a minha variavel e o 1 é a coluna da planilha.
'Se começasse na coluna "B" seria 2.Faça ate encontrar uma line vazia.

Dates = .Cells(line, 16).Value 'Dates é a variavel que criei + a variavel Line.
'Em que coluna esta a data em sua planilha? na Coluna "P"=16

If Dates >= txtReportDateStart And Dates <= txtReportEndDate Then 'Se a data inicial for maior que a data Final,


End If
If IsNumeric(.Cells(line, 23)) Then 'entao.
'Em que coluna esta OverDue em sua planilha? na Coluna "V"=23

Set li = listvBetweenDates.ListItems.Add(Text:=.Cells(line, "A").Value) 'Aqui estamos criando a variavel
'para a listvBetweenDates que é "li".

'li=listvBetweenDates
li.ListSubItems.Add Text:=.Cells(line, "B").Value 'Nao repetimos mais o nome completo da listView,apenas"li".
'Essa line sera carregada com o valor da coluna "B" da planilha.
li.ListSubItems.Add Text:=.Cells(line, "C").Value
li.ListSubItems.Add Text:=.Cells(line, "I").Value
li.ListSubItems.Add Text:=.Cells(line, "P").Value
li.ListSubItems.Add Text:=.Cells(line, "Q").Value
li.ListSubItems.Add Text:=Format(.Cells(line, "T").Value, "Currency")
li.ListSubItems.Add Text:=.Cells(line, "U").Value
li.ListSubItems.Add Text:=.Cells(line, "V").Value
li.ListSubItems.Add Text:=.Cells(line, "W").Value

linelist = linelist + 1 'Onde linelist é a variavel. A cada loop vai ser a linelist=linelist+1

End If

line = line + 1

Wend 'Wend é o fechamento de While.

End With

Call SomarListView
Call CountRecord


'############################################################

Sheet2.Select 'Enviar dados para a Planilha
Range("A1") = btnFilterDates.Caption 'Delayed
Range("E2") = lblTotal.Caption 'Levando a informacao da Label tem que colocar uma para cada botao.
Range("H2") = "Printed in: " & Now()
Range("E1") = lblTotalRecord.Caption




Dim inicio As Range
Dim i As Double

Set inicio = Sheet2.Range("A3") 'A3 é a coluna conde comeca receber os dados
'Usamos A3 para os dados iniciar na A4

With Sheet2

For i = 1 To listvBetweenDates.ListItems.Count 'Conta quantas lines tem na Listview
With inicio
.Cells(i + 1, 1) = listvBetweenDates.ListItems(i).Text 'Coluna "A" = Customer ID
'(i + 1)i= variavel e o + 1 para adicionar uma line apos a outra.
'(i + 1, 0) ,1 e a line da ListView Coluna A=0, Coluna B=1
'0 "zero"refere se a coluna "A" da Planilha


.Cells(i + 1, 2) = listvBetweenDates.ListItems(i).SubItems(1) 'Customer Account. SubItems(1)=Coluna da ListView)
.Cells(i + 1, 3) = listvBetweenDates.ListItems(i).SubItems(2) 'Customer Name
.Cells(i + 1, 4) = listvBetweenDates.ListItems(i).SubItems(3) 'Event Name
.Cells(i + 1, 5) = listvBetweenDates.ListItems(i).SubItems(4) 'Data do Event
.Cells(i + 1, 6) = listvBetweenDates.ListItems(i).SubItems(5) 'Service
.Cells(i + 1, 7) = listvBetweenDates.ListItems(i).SubItems(6) 'Amount
.Cells(i + 1, 8) = listvBetweenDates.ListItems(i).SubItems(7) 'DueDate
.Cells(i + 1, 9) = listvBetweenDates.ListItems(i).SubItems(8) 'Payment Date
.Cells(i + 1, 10) = listvBetweenDates.ListItems(i).SubItems(9) 'Over Due
End With

.Columns("B").HorizontalAlignment = xlCenter
.Columns("D").HorizontalAlignment = xlCenter
.Columns("E").HorizontalAlignment = xlCenter
.Columns("G").HorizontalAlignment = xlCenter
.Columns("H").HorizontalAlignment = xlCenter
.Columns("I").HorizontalAlignment = xlCenter

.Columns("A").ColumnWidth = 0
.Columns("B").ColumnWidth = 5.71
.Columns("C").ColumnWidth = 30
.Columns("D").ColumnWidth = 30
.Columns("E").ColumnWidth = 10
.Columns("F").ColumnWidth = 5.14
.Columns("G").ColumnWidth = 10
.Columns("H").ColumnWidth = 10
.Columns("I").ColumnWidth = 10
.Columns("J").ColumnWidth = 4.14
Next
End With
With ThisWorkbook.Sheets("Reports")
.Columns(5).Resize(.Rows.Count - 1, 1).Offset(1, 0).NumberFormat = "m/d/yyyy"
End With

End Sub


Disable adblock

This site is supported by ads and donations.
If you see this text you are blocking our ads.
Please consider a Donation to support the site.


Responder