Mostrando postagens com marcador VBA. Mostrar todas as postagens
Mostrando postagens com marcador VBA. Mostrar todas as postagens

5/24/2015

Mudar a cor da linha conforme a data

Mudar a cor conforme a data


este cola em modulo

Sub Macro1()

Dim linha As Integer

linha = 2

    While Range("A" & linha & ":" & "E" & linha).Select And ActiveCell <> ""
       
        If Range("A" & linha) < Date Then
   
            With Selection.Interior
                .ThemeColor = xlThemeColorAccent1
            End With
           
         End If
       
            linha = linha + 1
   
    Wend
   
End Sub

Sub Macro2()

Dim linha As Integer

linha = 2

    While Range("A" & linha & ":" & "E" & linha).Select And ActiveCell <> ""
       
        If Range("A" & linha) = Date Then
   
            With Selection.Interior
                .ThemeColor = xlThemeColorAccent2
            End With
           
         End If
       
            linha = linha + 1
   
    Wend
   
End Sub

Sub Macro3()

Dim linha As Integer

linha = 2

    While Range("A" & linha & ":" & "E" & linha).Select And ActiveCell <> ""
       
        If Range("A" & linha) > Date Then
   
            With Selection.Interior
                .ThemeColor = xlThemeColorAccent3
            End With
           
         End If
       
            linha = linha + 1
   
    Wend
   
End Sub


----------------------------------------------------------------------------------------------------

este cola em esta pasta

Private Sub Workbook_Open()

Call Módulo1.Macro1
Call Módulo1.Macro2
Call Módulo1.Macro3

End Sub

Para mudar a cor de linha par




Sub Macro1()

Dim linha As Integer

linha = 2

    While Range("A" & linha & ":" & "E" & linha).Select And ActiveCell <> ""
     
        If (linha Mod 2 = 0) Then
 
            With Selection.Interior
                .ThemeColor = xlThemeColorAccent1
            End With
         
         End If
       
            linha = linha + 1
 
    Wend
 
End Sub





adicionar também bordas
se for par e se for impar a diferença é que se for impar não muda a cor



Sub Macro1()

Dim linha As Integer

linha = 2

    While Range("A" & linha & ":" & "E" & linha).Select And ActiveCell <> ""
       
        If (linha Mod 2 = 0) Then
   
            With Selection.Interior
                .ThemeColor = xlThemeColorAccent1
            End With
            Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
         .Weight = xlThin
    End With
    With Selection.Borders(xlInsideVertical)
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
        .Weight = xlThin
    End With
   
   
   
    Else
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeRight)
         .Weight = xlThin
    End With
    With Selection.Borders(xlInsideVertical)
        .Weight = xlThin
    End With
    With Selection.Borders(xlInsideHorizontal)
        .Weight = xlThin
    End With
   
   
   
         End If
       
            linha = linha + 1
   
    Wend
   
End Sub

5/23/2015

Registrar ultimo acesso

colocar código em Esta_pasta_de_trabalho

primeiro comando manda executar antes de fechar

Private Sub Workbook_BeforeClose(Cancel As Boolean)

' chama acessos
acessos

End Sub

Sub acessos()

    'seleciona célula A1 da Planilha 1
    Sheets("Plan1").Cells(1, 1).Select

    'xl = ctrl e down para baixo, é como se clicasse ctrl e para baixo
    Selection.End(xlDown).Select

    se a célula com conteúdo ir para próxima
    linha = ActiveCell.Row + 1
 
    'escrever data e hora que ocorreu a ação de fechar neste caso
    Sheets("Plan1").Cells(linha, 1) = Now()

End Sub

Se celula diferente de vazia

Função se celula diferente de vazia


Tentativas....

Tentando configurar macro


5/22/2015

Declarar variável

'declarar variável, define quais dados podem
'ser armazenados dentro de cada variável

Dim x, y, z As String

'o de cima é igual a
'Dim x As String
'Dim y As String
'Dim z As String

Dim nome As Double
Dim teste1, teste2 As Integer
Dim ativo As Boolean


Tabela - Subtipos do tipo Variant disponíveis no VBA: 
Subtipo
Subtipo
Empty
O Valor é zero para variáveis numéricas ou uma String de tamanho zero (" "), para variáveis de texto.
Null
A variável não contém dados válidos.
Boolean
Contém variáveis que somente podem assumir dois valores:Verdadeiro ou Falso (True ou False).
Byte
Valor inteiro, na faixa de 0 até 255.
Integer
Valor inteiro, na faixa de -32768 até 32767.
Currency
Valores na faixa de -923.337.203.685.447,5808 até 922.337.203.685.447,5807
Long
Valor inteiro, na faixa de -2.147.483.648 até 2.147.483.647.
Date(Time)
É um número que representa a data entre 01 de Janeiro do ano 100, até 31 de Dezembro de 9999 (Olha o bug do ano 10000 chegando).
String
Texto de tamanho variável, pode conter, aproximadamente, 2 bilhões de caracteres.
Object
Pode conter um objeto qualquer, como um Controle Activex, ou um Objeto COM+
Error
Pode conter um número de erro.

Identer organizar códigos vba

link 1
link 2


para garantir


Adicionar data
abrir prompt como admin
ir até a pasta contendo o arquivo
autorizar
regsvr32 mscomct2.ocx (nome do arquivo)

Link 1
Link 2

5/21/2015

condição com valor vba

condicional para mudar fonte e fundo de acordo com o valor

Private Sub Worksheet_Change(ByVal Target As Range)
If Sheets(1).Cells(1, 1) = celula Then
 
    Sheets(1).Cells(1, 1).Font.ColorIndex = 1
    Sheets(1).Cells(1, 1).Interior.ColorIndex = 0
 
    Else
    Sheets(1).Cells(1, 1).Font.ColorIndex = 2
    Sheets(1).Cells(1, 1).Interior.ColorIndex = 1
 
    End If
End Sub