About Me
Com tecnologia do Blogger.
Seguidores
Estatisticas
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
2005-06-27
A função EOMONTH(), que se encontra no Analysis ToolPak add-in, devolve o número de série correspondente ao último dia do mês que é apurado somando ou diminuindo o número de meses pretendido ao mês que serve de base, sendo a sintaxe a seguinte: EOMONTH(start_date,months).
No entanto, se não se tiver o add-in mencionado, pode efectuar-se o mesmo tipo de cálculo, utilizando as funções DATE(), YEAR() e MONTH() em conjunto. A única diferença é que no segundo caso, temos que adicionar ou subtrair 1 mês, para podermos obter o mesmo resultado:


Nota: as células B1 e B3 estão formatadas como data, porque se estiverem formatadas como geral, a devolução é o número de série.
No entanto, se não se tiver o add-in mencionado, pode efectuar-se o mesmo tipo de cálculo, utilizando as funções DATE(), YEAR() e MONTH() em conjunto. A única diferença é que no segundo caso, temos que adicionar ou subtrair 1 mês, para podermos obter o mesmo resultado:
Nota: as células B1 e B3 estão formatadas como data, porque se estiverem formatadas como geral, a devolução é o número de série.
2005-06-16
Marina Limeira (Forum brasileiro de Office), perguntou como seria possível escolher um fundo da folha de cálculo, de acordo com a seguinte alternativa:
Se fosse maior (>) que 50, o fundo seria uma imagem; se fosse inferior ou igual (<=) a 50, então a imagem seria outra.
Utlizando o Evento SelectionChange, podemos ter o seguinte resultado:
> 50:

<=50:

O Código:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("A1") > 50 Then
Worksheets("Folha1").SetBackgroundPicture "E:\camaleão5.jpg"
Else
Worksheets("Folha1").SetBackgroundPicture "E:\butterflies.jpg"
End If
End Sub
Se fosse maior (>) que 50, o fundo seria uma imagem; se fosse inferior ou igual (<=) a 50, então a imagem seria outra.
Utlizando o Evento SelectionChange, podemos ter o seguinte resultado:
> 50:
<=50:
O Código:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("A1") > 50 Then
Worksheets("Folha1").SetBackgroundPicture "E:\camaleão5.jpg"
Else
Worksheets("Folha1").SetBackgroundPicture "E:\butterflies.jpg"
End If
End Sub
Subscrever:
Mensagens (Atom)