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.
  • Avatar do usuário
  • Avatar do usuário
Avatar do usuário
Por GENECI
Avatar
#55669
Boa tarde.

Solicito a sua ajuda, conforme instruções no arquivo anexo.

Grato - GENECI.
Você não está autorizado a ver ou baixar esse anexo.
Avatar do usuário
Por mucascosta
Posts Avatar
#55673
Código: Selecionar todos
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Address() = "$B$1" Then
  Range("A1").Value = Range("A1").Value + 1
ElseIf ActiveCell.Address() = "$C$1" Then
  Range("A1").Value = Range("A1").Value - 1
End If
End Sub
Código: Selecionar todos
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
If ActiveCell.Address() = "$B$1" Then
  Range("A1").Value = Range("A1").Value + 1
ElseIf ActiveCell.Address() = "$C$1" Then
  Range("A1").Value = Range("A1").Value - 1
End If
End Sub
Avatar do usuário
Por GENECI
Avatar
#55686
O segundo código não funcionou.

Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
If ActiveCell.Address() = "$B$1" Then
Range("A1").Value = Range("A1").Value + 1
ElseIf ActiveCell.Address() = "$C$1" Then
Range("A1").Value = Range("A1").Value - 1
End If
End Sub

Bom dia.
Muito obrigado por elaborar o código.
Que atende parcialmente a minha necessidade, como citei vou trabalhar apenas com as três células.
A1 B1 C1.
Na atual situação, o código faz o seguinte, quando clico na célula B1 adiciona um número ok está correto, para adicionar mais um número, necessito sair da célula B1 e retornar a mesma célula, eu quero permanecer na célula e clicar com o botão direito do mouse.
Por favor pode revisar o código.

Grato - Geneci.
Por osvaldomp
#55697
Olá, Geneci.

Veja se os códigos abaixo atendem.
Código: Selecionar todos
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
 If Target.Address = "$B$1" Then
  [A1] = [A1] + 1: Cancel = True
 ElseIf Target.Address = "$C$1" Then
  [A1] = [A1] - 1: Cancel = True
 End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 If Target.Address = "$B$1" Then
  [A1] = [A1] + 1
 ElseIf Target.Address = "$C$1" Then
  [A1] = [A1] - 1
 End If
End Sub
Ou os dois abaixo como alternativa.
Código: Selecionar todos
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
 [A1] = [A1] + (Target.Address = "$B$1") * -1 + (Target.Address = "$C$1")
 Cancel = (Target.Address = "$B$1") * -1 + (Target.Address = "$C$1")
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 [A1] = [A1] + (Target.Address = "$B$1") * -1 + (Target.Address = "$C$1")
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