Corrigir Campo formulário

Olá. Em um campo do formulário por padrão é zero (Custo), porém , quando o campo anterior é “V”, preciso impedir o cadastro (macro) do “custo” 0,00 e voltar 'a caixa para alterar antes de cadastrar. Já tentei com If, IfElse, And está registrando 0,00 mesmo assim. Alguém tem uma solução? Grato.

Preciso impedir o cadastro 0,00 em “Custo” caso o campo anterior seja “V” venda

Estes campos podem ser vinculados em células, então a macro CADASTRAR, olha a primeira célula, se “V”, olha a segunda e se for 0,00, retorna uma mensagem de Erro e interrompe o Cadastramento.


Para uma AJUDA mas precisa, poste um arquivo exemplo, retire dados sigilosos.

Estou no Básico, apanhando muito…

Sub CadastrarDT

plan_Acoes_DayTrade = ThisComponent.Sheets.getByName( "Acoes_DayTrade" )
numeroLinhaCadastrar_DT = ultimaLinha ( "Acoes_DayTrade", "A:A")

if CorretoraCadDT.Text = “” then
msgBox ( “Informe a Corretora”, 0 + 64 , “AVISO” )
CorretoraCadDT.SetFocus
Exit Sub
end if

if NotaCadDT.Text = “” then
msgBox ( “Nº da Nota É OBRIGATÓRIO”, 0 + 64 , “AVISO” )
NotaCadDT.SetFocus
Exit Sub
end if

if TickerCadDT.Text = “” then
msgBox ( “Código do Ativo É OBRIGATÓRIO”, 0 + 64 , “AVISO” )
TickerCadDT.SetFocus
Exit Sub
end if

if PregaoCadDT.Text = “” then
msgBox ( “Data da Operação É OBRIGATÓRIO”, 0 + 64 , “AVISO” )
PregaoCadDT.SetFocus
Exit Sub
end if

if LiquidCadDT.Text = “” then
msgBox ( “Data da Liquidação É OBRIGATÓRIO”, 0 + 64 , “AVISO” )
LiquidCadDT.SetFocus
Exit Sub
end if

if ComVenCadDT.Text = “” then
msgBox ( “Digite: ‘C’ p/ Compra, ‘V’ p/ Venda. Campo OBRIGATÓRIO”, 0 + 64 , “AVISO” )
ComVenCadDT.SetFocus
Exit Sub
end if

if CustoMedioCadDT.Text = “” then
msgBox ( “Custo Médio É OBRIGATÓRIO para VENDA”, 0 + 64 , “AVISO” )
CustoMedioCadDT.SetFocus
stop
end if

if QtdeCadDT.Text = “” then
msgBox ( “Quantidade É OBRIGATÓRIO”, 0 + 64 , “AVISO” )
QtdeCadDT.SetFocus
stop
end if

if PrecoCadDT.Text = “” then
msgBox ( “Preço É OBRIGATÓRIO”, 0 + 64 , “AVISO” )
PrecoCadDT.SetFocus
stop
end if

if TaxaCadDT.Text = “” then
msgBox ( “Taxa É OBRIGATÓRIO”, 0 + 64 , “AVISO” )
TaxaCadDT.SetFocus
stop
end if

if ImpRRF_CadDT.Text = “” then
msgBox ( “I.R.R.F. É OBRIGATÓRIO”, 0 + 64 , “AVISO” )
ImpRRF_CadDT.SetFocus
stop
end if

Dim codigo_retorno as integer

codigo_retorno = msgBox ( "Custo é Obrigatório para VENDA. " + chr$(13) + “Retorna para Custo Médio ?”, 4 + 16 + 128, “ALERTA Day-Trade”)

If codigo_retorno = 6 Then

	CustoMedioCadDT.SetFocus

Stop
Else
End If

'linha 176 - LANÇA OS DADOS NA PLANILHA
'==========================================================
With plan_Acoes_DayTrade

.getCellByPosition(0, numeroLinhaCadastrar_DT ).Value = PregaoCadDT.Text
.getCellByPosition(1, numeroLinhaCadastrar_DT ).Value = LiquidCadDT.Text
.getCellByPosition(2, numeroLinhaCadastrar_DT ).String = TickerCadDT.Text
.getCellByPosition(3, numeroLinhaCadastrar_DT ).String = ComVenCadDT.Text
.getCellByPosition(4, numeroLinhaCadastrar_DT ).String = CorretoraCadDT.Text
.getCellByPosition(5, numeroLinhaCadastrar_DT ).String = NotaCadDT.Text
.getCellByPosition(6, numeroLinhaCadastrar_DT ).String = CustoMedioCadDT.Text
.getCellByPosition(7, numeroLinhaCadastrar_DT ).Value = QtdeCadDT.Text
.getCellByPosition(8, numeroLinhaCadastrar_DT ).String = PrecoCadDT.Text
.getCellByPosition(10, numeroLinhaCadastrar_DT ).String = TaxaCadDT.Text
.getCellByPosition(14, numeroLinhaCadastrar_DT ).String = ImpRRF_CadDT.Text
.getCellByPosition(18, numeroLinhaCadastrar_DT ).String = numeroLinhaCadastrar_DT + 1

End With

ThisComponent.Store ’ salva na planilha
msgBox ( “Cadastrado com Sucesso”, 0 + 64 , “AVISO” )

CorretoraCadDT.SetFocus

End sub

Sub pesquisar_NotaCadDT

	plan_Acoes_DayTrade = ThisComponent.Sheets.getByName( "Acoes_DayTrade" )
	notas_cadastradasDT = ultimaLinha ( "Acoes_DayTrade", "A:A") - 1**strong text**

Ola @LCB1, eu uso uma maneira diferente com uso de de Opções de formulários, eu vínculos todos os campos em células, em algum lugar, na mesma sequencia do banco de dados. quando tudo preenchido, a macro CADASTRAR ( pode ou não fazer conferencia de informações ) copia estas células para o banco de dados, todos em única vez.


Tente incluir esta parte após o CustoMedio

If ComVenCadDT.Text = "V" Then 
	If CustoMedioCadDT.Text = 0.00 Then
		msgBox "Custo Médio não pode ser zero", 0 + 64 , "AVISO"
		CustoMedioCadDT.SetFocus
	Stop
	EndIf 
EndIf

Acrescentei.


Negativo

Melhor solução que encontrei (linha 118…127), mas ainda permite cadastrar com custo 0,000