- 24 Ago 2019 às 15:10
#47314
Não consigo rodar a função abaixo com a variável cont1
Obrigado
Private Sub Gerar_Click()
Dim cont As Integer
cont = ContarRegistro(Worksheets("Planilha Ativa").Range(Cells(10, 2), Cells(28, 2)))
Dim cont1 As Integer
cont1 = ContarRegistro(Worksheets("Outra Planilha").Range(Cells(10, 2), Cells(28, 2)))
O primeiro funciona e no segundo ocorre um erro: Erro em tempo de execução 1004
Erro de definição de aplicativo ou de definição de objeto
End Sub
Public Function ContarRegistro(area As Range) As Long
Dim celula As Range, TotalLinhas As Long
TotalLinhas = 0
For Each celula In area
If celula <> "" Then
TotalLinhas = TotalLinhas + 1
End If
Next
ContarRegistro = TotalLinhas
End Function
Obrigado
Private Sub Gerar_Click()
Dim cont As Integer
cont = ContarRegistro(Worksheets("Planilha Ativa").Range(Cells(10, 2), Cells(28, 2)))
Dim cont1 As Integer
cont1 = ContarRegistro(Worksheets("Outra Planilha").Range(Cells(10, 2), Cells(28, 2)))
O primeiro funciona e no segundo ocorre um erro: Erro em tempo de execução 1004
Erro de definição de aplicativo ou de definição de objeto
End Sub
Public Function ContarRegistro(area As Range) As Long
Dim celula As Range, TotalLinhas As Long
TotalLinhas = 0
For Each celula In area
If celula <> "" Then
TotalLinhas = TotalLinhas + 1
End If
Next
ContarRegistro = TotalLinhas
End Function