Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
#57143
Boa tarde!
Estou desenvolvendo um pequeno sistema usando o inputbox. Refiz todo o código e pra cadastrar apareceu o seguinte erro:

"A variável do objeto ou a varíavel do bloco With não foi definida"

Eis o código:

Option Explicit

Sub cadastro()

Dim vlmatricula As Variant
Dim vlnome As Variant
Dim vltpsang As Variant
Dim linOpt As Long
Dim vlrCadastro As Worksheet

With vlrCadastro
Do
vlmatricula = InputBox("Informe a matrícula: ")
Loop While vlmatricula = vbNullString

Do
vlnome = InputBox("Informe o nome: ")
Loop While vlnome = vbNullString

Do
vltpsang = InputBox("Informe o Tipo Sanguíneo: ")
Loop While vltpsang = vbNullString

linOpt = .Range("A1").End(xlUp).Row + 1 <- erro está aqui!

.Cells(linOpt, 1) = vlmatricula
.Cells(linOpt, 2) = vlnome
.Cells(linOpt, 3) = vltpsang
End With
End Sub

Se alguém possa me ajudar nesse sentido, ficarei agradecido!
Aguardo respostas! []'s
#57149
Se vlrCadastro for o codename da planilha
Código: Selecionar todos
Option Explicit

Sub cadastro()

Dim vlmatricula As Variant
Dim vlnome As Variant
Dim vltpsang As Variant
Dim linOpt As Long

With vlrCadastro
Do
vlmatricula = InputBox("Informe a matrícula: ")
Loop While vlmatricula = vbNullString

Do
vlnome = InputBox("Informe o nome: ")
Loop While vlnome = vbNullString

Do
vltpsang = InputBox("Informe o Tipo Sanguíneo: ")
Loop While vltpsang = vbNullString

linOpt = .Range("A1").End(xlUp).Row + 1 <- erro está aqui!

.Cells(linOpt, 1) = vlmatricula
.Cells(linOpt, 2) = vlnome
.Cells(linOpt, 3) = vltpsang
End With
End Sub
Se vlrCadastro não for um codename da planilha e sim uma variável qual deverá ser atribuída uma planilha:
Código: Selecionar todos
Option Explicit

Sub cadastro()

Dim vlmatricula As Variant
Dim vlnome As Variant
Dim vltpsang As Variant
Dim linOpt As Long
Dim vlrCadastro As Worksheet

Set vlrCadastro = Thisworkbook.Worksheets("Nome da sua planilha")

With vlrCadastro
Do
vlmatricula = InputBox("Informe a matrícula: ")
Loop While vlmatricula = vbNullString

Do
vlnome = InputBox("Informe o nome: ")
Loop While vlnome = vbNullString

Do
vltpsang = InputBox("Informe o Tipo Sanguíneo: ")
Loop While vltpsang = vbNullString

linOpt = .Range("A1").End(xlUp).Row + 1 <- erro está aqui!

.Cells(linOpt, 1) = vlmatricula
.Cells(linOpt, 2) = vlnome
.Cells(linOpt, 3) = vltpsang
End With
End Sub
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord