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
#6135
Srs, possuo o seguinte codigo, hoje ele formata a linha sempre que uma celula daquila linha é selecionada.
Gostaria de colocar uma função para Ativar e Desativar, tipo, se a celula A1 = "Ativado", ai o codigo é ativado e fica funcional, caso contrario fique inativo.
Podem ajudar?

Codigo:
Option Explicit
Public Sub HighlightTableRow(Target As Excel.Range)

Dim t As ListObject
Dim lngInTable As Long
Dim c As Long

Const COLOR_SELECT = 1
Const COLOR_LIGHTER = 0.4

On Error Resume Next

If Target.Interior.Pattern = xlPatternSolid Then Exit Sub

For Each t In Target.Parent.ListObjects
c = c + 1
If Not Intersect(Target, t.DataBodyRange) Is Nothing Then
lngInTable = c
End If
t.Range.Interior.Pattern = xlNone
Next
If lngInTable = 0 Then Exit Sub

With Target.Parent.ListObjects(lngInTable)
With .Range.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With .DataBodyRange
With .Resize(Target.Rows.Count).Offset(Target.Row - .Row).Interior
.ThemeColor = COLOR_SELECT
.TintAndShade = 1 - COLOR_LIGHTER
End With
End With
End With

End Sub
#6382
Boa tarde!!

Seria isso?
Código: Selecionar todos
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    Cells.Interior.ColorIndex = xlColorIndexNone
    ActiveCell.EntireRow.Interior.ColorIndex = 36
End Sub
Obs: O código deve ser posto no módulo de planilha.

Fonte:
http://www.vbaexpress.com/kb/getarticle.php?kb_id=145
Att
Avatar do usuário
Por Parkeless
Posts Avatar
#6384
Se é só para o código não ativar se o conteúdo da célula A1 não for "Ativado", só incluir na primeira linha do seu código:
Código: Selecionar todos
If range("A1") <> "Ativado" then: Exit 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