- 12 Dez 2018 às 12:46
#39252
Boa Tarde,
A rotina abaixo é pra percorrer uma coluna, de um cabeçalho pré-selecionado. Quando a hora da célula for 1seg menor do que a célula debaixo, mando excluir a linha da célula debaixo. Porém, na comparação, mesmo os valores estando iguais e com o mesmo formato, o programa está pulando o IF direto pro ELSE, sem realizar a exclusão da linha.
Sub excl_seq()
Application.ScreenUpdating = False
Dim lin As Long
Dim col As Long
Dim last As Long
Dim seg As Date
Dim x As Date
Dim y As Date
Dim Z As Date
Dim ySheet As Worksheet
Set ySheet = ActiveWorkbook.ActiveSheet
last = ySheet.UsedRange.Rows.Count
lin = ActiveCell.Row
col = ActiveCell.Column
seg = CDate("00:00:01")
With ySheet
While lin < last
x = Cells(lin + 1, col).Value
x = CDate(x)
y = Cells(lin, col).Value
y = CDate(y)
lapos = lin + 1
Z = y + seg
If Z = x Then
.Rows(lapos).Delete
Else
lin = lin + 1
End If
Wend
End With
Application.ScreenUpdating = True
End Sub
https://imgur.com/a/O3CVel4
https://imgur.com/a/9okL7u8
A rotina abaixo é pra percorrer uma coluna, de um cabeçalho pré-selecionado. Quando a hora da célula for 1seg menor do que a célula debaixo, mando excluir a linha da célula debaixo. Porém, na comparação, mesmo os valores estando iguais e com o mesmo formato, o programa está pulando o IF direto pro ELSE, sem realizar a exclusão da linha.
Sub excl_seq()
Application.ScreenUpdating = False
Dim lin As Long
Dim col As Long
Dim last As Long
Dim seg As Date
Dim x As Date
Dim y As Date
Dim Z As Date
Dim ySheet As Worksheet
Set ySheet = ActiveWorkbook.ActiveSheet
last = ySheet.UsedRange.Rows.Count
lin = ActiveCell.Row
col = ActiveCell.Column
seg = CDate("00:00:01")
With ySheet
While lin < last
x = Cells(lin + 1, col).Value
x = CDate(x)
y = Cells(lin, col).Value
y = CDate(y)
lapos = lin + 1
Z = y + seg
If Z = x Then
.Rows(lapos).Delete
Else
lin = lin + 1
End If
Wend
End With
Application.ScreenUpdating = True
End Sub
https://imgur.com/a/O3CVel4
https://imgur.com/a/9okL7u8