About Me
Com tecnologia do Blogger.
Seguidores
Estatisticas
2005-09-24
Para subtrair duas datas, de modo a que o resultado seja dado em anos, meses e dias, como no exemplo:

Podemos utilizar a seguinte fórmula com a função DATEDIF() :
=DATEDIF(A1;A2;"Y") & " ano(s), " & DATEDIF(A1;A2;"ym") & " mês(es) e " & DATEDIF(A1;A2;"md") & " dia(s) "

Podemos utilizar a seguinte fórmula com a função DATEDIF() :
=DATEDIF(A1;A2;"Y") & " ano(s), " & DATEDIF(A1;A2;"ym") & " mês(es) e " & DATEDIF(A1;A2;"md") & " dia(s) "
2005-09-03
Se pretendermos criar uma sequência aleatória de letras e números, como no exemplo

podemos utilizar algumas Funções em VBE.
O Código:
Sub GerarLetrasNumeros()
Dim obj As Object
Dim linha As Integer, coluna As Integer
Dim r As Integer, c As Integer
Set obj = Range("A1")
linha = obj.Row
coluna = obj.Column
For r = 0 To 10
For c = 0 To 5
Cells(linha + r, coluna + c).Value = Chr(65 + Int(10 * Rnd)) _
& Chr(65 + Int(10 * Rnd)) & Chr(65 + Int(10 * Rnd)) _
& Chr(48 + Int(10 * Rnd)) & Chr(48 + Int(10 * Rnd)) _
& Chr(48 + Int(10 * Rnd))
Next c
Next r
End Sub

podemos utilizar algumas Funções em VBE.
O Código:
Sub GerarLetrasNumeros()
Dim obj As Object
Dim linha As Integer, coluna As Integer
Dim r As Integer, c As Integer
Set obj = Range("A1")
linha = obj.Row
coluna = obj.Column
For r = 0 To 10
For c = 0 To 5
Cells(linha + r, coluna + c).Value = Chr(65 + Int(10 * Rnd)) _
& Chr(65 + Int(10 * Rnd)) & Chr(65 + Int(10 * Rnd)) _
& Chr(48 + Int(10 * Rnd)) & Chr(48 + Int(10 * Rnd)) _
& Chr(48 + Int(10 * Rnd))
Next c
Next r
End Sub
2005-08-18
Se pretendermos somar dois tipos de ocorrências, como no exemplo

podemos criar uma pequena fórmula, utilizando as Funções SUM() e COUNTIF(), esta última, com um array.
O Código:
=SUM(COUNTIF(A1:A20;{"bom";"muito bom"}))

podemos criar uma pequena fórmula, utilizando as Funções SUM() e COUNTIF(), esta última, com um array.
O Código:
=SUM(COUNTIF(A1:A20;{"bom";"muito bom"}))
2005-08-16
Se pretendermos que o utilizador digite, por exemplo, na célula "A1", valores que não sejam negativos ou zero, como no exemplo:


podemos socorrer-nos de um pouco de VBA.
O Código:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If IsEmpty(Range("A1")) Then
Exit Sub
End If
If Range("A1") < 0 Then
MsgBox "O valor não pode ser negativo! Tente outra vez!!!"
Range("A1").ClearContents
ElseIf Range("A1") = 0 Then
MsgBox "O valor não pode ser zero! Tente outra vez!!!"
Range("A1").ClearContents
Else
Exit Sub
End If
End Sub


podemos socorrer-nos de um pouco de VBA.
O Código:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If IsEmpty(Range("A1")) Then
Exit Sub
End If
If Range("A1") < 0 Then
MsgBox "O valor não pode ser negativo! Tente outra vez!!!"
Range("A1").ClearContents
ElseIf Range("A1") = 0 Then
MsgBox "O valor não pode ser zero! Tente outra vez!!!"
Range("A1").ClearContents
Else
Exit Sub
End If
End Sub
2005-08-12
Se pretendermos efectuar cálculos com horas, em que a hora de início é superior à hora do fim (no pressuposto que esta última é já no dia seguinte) podemos utilizar a seguinte fórmula em Excel:

2005-08-01
O Código:
Sub Auto_Open()
Dim num As Integer
num = ActiveWorkbook.Worksheets.Count
ActiveWorkbook.Worksheets(num).Activate
End Sub
Sub Auto_Open()
Dim num As Integer
num = ActiveWorkbook.Worksheets.Count
ActiveWorkbook.Worksheets(num).Activate
End Sub
2005-07-26
Se pretendermos que, em determinada coluna, os números negativos sejam apresentados a BOLD, como no exemplo,


podemos utilizar um pouco de VBA.
O Código:
Private Sub CommandButton1_Click()
Sheets("Sheet1").Select
Columns("A:A").Select
On Error Resume Next
Call CheckCells(Selection.SpecialCells(xlConstants, 23))
Call CheckCells(Selection.SpecialCells(xlFormulas, 23))
Range("b1").Select
End Sub
Sub CheckCells(CurrRange As Range)
For Each cell In CurrRange
If cell.Value < 0 Then
cell.Font.Bold = True
End If
If cell.Value >= 0 Then
cell.Font.Bold = False
Selection.Interior.ColorIndex = 0
End If
Next cell
End Sub


podemos utilizar um pouco de VBA.
O Código:
Private Sub CommandButton1_Click()
Sheets("Sheet1").Select
Columns("A:A").Select
On Error Resume Next
Call CheckCells(Selection.SpecialCells(xlConstants, 23))
Call CheckCells(Selection.SpecialCells(xlFormulas, 23))
Range("b1").Select
End Sub
Sub CheckCells(CurrRange As Range)
For Each cell In CurrRange
If cell.Value < 0 Then
cell.Font.Bold = True
End If
If cell.Value >= 0 Then
cell.Font.Bold = False
Selection.Interior.ColorIndex = 0
End If
Next cell
End Sub
2005-07-19
Se pretendermos criar uma mensagem de informação a partir de um botão de comando, como no exemplo seguinte,

podemos utilizar um pouco de VBA.
O Código:
Private Sub CommandButton1_Click()
Dim Ops(1 To 3) As String
Dim Msg As String
Dim Texto As String
Application.Cursor = xlNormal
Ops(1) = "Elaborado por: "
Ops(2) = "EXCELer, "
Ops(3) = "Vilamoura, Julho de 2005"
Texto = Ops(1) + vbCr
Texto = Texto + Ops(2) + vbCr
Texto = Texto + Ops(3)
Msg = MsgBox(Texto, Buttons:=vbInformation, Title:="AUTOR")
Select Case Msg
End Select
End Sub

podemos utilizar um pouco de VBA.
O Código:
Private Sub CommandButton1_Click()
Dim Ops(1 To 3) As String
Dim Msg As String
Dim Texto As String
Application.Cursor = xlNormal
Ops(1) = "Elaborado por: "
Ops(2) = "EXCELer, "
Ops(3) = "Vilamoura, Julho de 2005"
Texto = Ops(1) + vbCr
Texto = Texto + Ops(2) + vbCr
Texto = Texto + Ops(3)
Msg = MsgBox(Texto, Buttons:=vbInformation, Title:="AUTOR")
Select Case Msg
End Select
End Sub
2005-07-10
Por vezes, temos necessidade de criar um registo de entradas em determinado workbook, que, para além de conter o nome do utilizador, poderá ainda conter a data e a hora do acesso:

Resultado:

O Código:
Sub Auto_Open()
Dim Ops(1 To 5) As String
Dim msg As String
Ops(1) = Day(Date)
Ops(2) = Month(Date)
Ops(3) = Year(Date)
Ops(4) = Hour(Time)
Ops(5) = Minute(Time)
msg = Ops(3) & "-" & Ops(2) & "-" & Ops(1) & " " & Ops(4) & ":" & Ops(5)
Sheets("Sheet1").Select
Range("A65536").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
Application.Cursor = xlNormal
Do While IsEmpty(ActiveCell)
ActiveCell.FormulaR1C1 = InputBox(Prompt:="Introduza o seu NOME:", _
Title:="Nome do Utilizador")
ActiveCell.FormulaR1C1 = UCase(ActiveCell)
Loop
Range("B65536").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = msg
End
End Sub

Resultado:

O Código:
Sub Auto_Open()
Dim Ops(1 To 5) As String
Dim msg As String
Ops(1) = Day(Date)
Ops(2) = Month(Date)
Ops(3) = Year(Date)
Ops(4) = Hour(Time)
Ops(5) = Minute(Time)
msg = Ops(3) & "-" & Ops(2) & "-" & Ops(1) & " " & Ops(4) & ":" & Ops(5)
Sheets("Sheet1").Select
Range("A65536").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
Application.Cursor = xlNormal
Do While IsEmpty(ActiveCell)
ActiveCell.FormulaR1C1 = InputBox(Prompt:="Introduza o seu NOME:", _
Title:="Nome do Utilizador")
ActiveCell.FormulaR1C1 = UCase(ActiveCell)
Loop
Range("B65536").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = msg
End
End Sub
2005-07-04
Se pretendermos que, ao abrir um workbook, nos seja pedido para digitarmos o nome do utilizador, podemos utilizar o seguinte exemplo:


O Código:
Sub Auto_Open()
Range("B1").Value = Application.InputBox("Escreva o seu nome")
End Sub


O Código:
Sub Auto_Open()
Range("B1").Value = Application.InputBox("Escreva o seu nome")
End Sub
Subscrever:
Mensagens (Atom)