Pesquisar neste blog

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

04/12/2020

Formulário com ListBox em Excel VBA #02

Excel 2010





























Private Sub btnInserir_Click()
Dim lista As Long

With lbdados

lista = 0
'contagem da lista, se a lista for diferente de 0'
If lbdados.ListCount <> 0 Then lista = (lbdados.ListCount + 1) - 1

.AddItem

'trabalhando com Lista'
.List(lista, 0) = Me.txnome.Value 'linha 0, coluna 0'
.List(lista, 1) = Me.txidade.Value
.List(lista, 2) = Me.txendereco.Value

End With

End Sub

22/11/2020

Formulário ProgressBar com Excel VBA












































Código feito em Visual Macro

Private Sub btn_somar_Click()

Dim soma As Long

'Carregando na mesma proporção
Me.pg_status.Min = 2
Me.pg_staus.Max = 31

For cont = 2 To 31

Me.pg_status.Value = cont 'irá acompanhar o progresso
soma = Plan1.Cells(cont, 1) + Plan1.Cells(cont, 2)

'Lançando os dados na planilha da coluna C
Plan1.Cells(cont, 3).Value = soma

Next

MsgBox "OPERAÇÃO REALIZADA"

End Sub

Formulário de análise em Excel VBA #01




Código1 feito na Visual Macro

Sub relatorio()

Dim produtos_vendidos As Long
Dim produtos_totais As Long

produtos_vendidos = WorksheetFunction.CountIf(Plan3.Columns("c"), "SIM")
produtos_totais = WorksheetFunction.CountA(Plan3.Columns("a")) - 1

UserForm1.txtotais.Value = produtos_totais
UserForm1.txvendidos.Value = produtos_vendidos

MsgBox "ANÁLISE REALIZADA !", vbInformation, ""

End Sub



Fazendo formulário em Excel VBA #03

Excel 2010




















Código utilizado:

Private Sub ToggleButton1_Click()

'variáveis
Dim num1 As Long
Dim num2 As Long

'atribui valor que estiver na caixa de texto

num1 = Me.tx1.Value
num2 = Me.tx2.Value

Me.txResultado.Value = num1 * num2

MsgBox "Operação realizada com sucesso"

End Sub

15/11/2020

Sintetizador de voz com Macro em Excel VBA

Excel 2010



























Private Sub UserForm_Activate()

Dim hora As String
Dim qtprodutosnv As Long

qtprodutosnv = WorksheetFunction.CountIf(Plan1.Columns(3), "NÃO")

'Irá capturar a data atual
hora = Format(Now, "hh:mm")

'sintetizador de voz
Application.Speech.Speak ("OLÁ MUNDO !")

'Avisa a hora atual em voz
Application.Speech.Speak ("AGORA SÃO " & hora)

'Emite a voz dizendo a quantidade de produtos para vender
Application.Speech.Speak ("VOCE POSSUI " & qtprodutosnv & "PRODUTOS PARA VENDER EM SEU ESTOQUE !")

'fechando o formulário


End Sub

Mensagem com box em Excel VBA

Excel 2010























Sub testes()

MsgBox "OPERAÇÃO REALIZADA COM SUCESSO !", vbInformation
MsgBox "ERRO !", vbCritical
MsgBox "ALERTA !", vbExclamation

'2° parte superior da caixa
MsgBox "CUIDADO !", vbExclamation, "SISTEMA DE GESTÃO 4.0"

End Sub

Impressão, atalhos, ocultar e esconder planilha no Excel VBA

Excel 2016


























Sub imprimir()

'imprimindo os conteúdos da planilha 3
Plan3.PrintOut

MsgBox "PLANILHAS IMPRIMIDAS COM SUCESSO !"

End Sub


'Método para ocultar
Sub ocultar()

Plan1.Visible = False

End Sub

'Método para exibir
Sub desocultar()

Plan1.Visible = True

End Sub

14/11/2020

Estrutura Condicional em Excel VBA

Excel 2016


























Sub relatorio()

Dim vtotal As Long
Dim ltotal As Long

For contlinhas = 2 To 20

vtotal = Cells(contlinhas, 2).Value
ltotal = Cells(contlinhas, 3).Value

Cells(contlinhas, 4).Value = vtotal - ltotal

Next

For contlinhas = 2 To 20

vtotal = Cells(contlinhas, 2).Value
ltotal = Cells(contlinhas, 3).Value

Cells(contlinhas, 4).Value = vtotal - ltotal
Cells(contlinhas, 5).Value = ltotal / vtotal

If ltotal / vtotal > 0.55 Then

Cells(contlinhas, 6).Value = "SIM"

Else

Cells(contlinhas, 6).Value = "NÃO"

End If
Next

End Sub

13/11/2020

Estrutura de repetição FOR em Excel VBA

Excel 2010



























Sub relatorio()

Dim vtotal As Long
Dim ltotal As Long

For contlinhas = 2 To 20

vtotal = Cells(contlinhas, 2).Value
ltotal = Cells(contlinhas, 3).Value

Cells(contlinhas, 4).Value = vtotal - ltotal

Next

For contlinhas = 2 To 20

vtotal = Cells(contlinhas, 2).Value
ltotal = Cells(contlinhas, 3).Value

Cells(contlinhas, 4).Value = vtotal - ltotal
Cells(contlinhas, 5).Value = ltotal / vtotal

Next

End Sub

10/11/2020

Variáveis em Excel VBA

Excel 2010




Sub testarVariaveis()

Dim nome As String
Dim idade As Integer

nome = "Henrique"
idade = 34

MsgBox ("seu nome é: " & nome & " Sua idade = " & idade & " anos")

End Sub

05/11/2020

Método End em Excel VBA




























Private Sub Worksheet_SelectionChange(ByVal Target As Range)

ActiveCell.End(xlDown).Select

End Sub

________//________

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

ActiveCell.End(xlUp).Select

End Sub

04/11/2020

Método Offset em Excel VBA
































Private Sub Worksheet_SelectionChange(ByVal Target As Range)

ActiveCell.Offset(1, 0).Value = "Abaixo"

ActiveCell.Offset(-2, 1).Value = "Abaixo"

End Sub

03/11/2020

Eventos da planilha com Excel VBA #01

Excel 2010

























Private Sub Worksheet_SelectionChange(ByVal Target As Range)

ActiveCell.Value = "ALTERADO"

End Sub

Excel 2010



























Private Sub Worksheet_SelectionChange(ByVal Target As Range)

MsgBox Target.Address
MsgBox Target.Row
MsgBox Target.Column

End Sub

Funções na planilha com Excel VBA #02

Excel 2010



























Sub total()

Range("f3").Value = WorksheetFunction.CountA(Plan1.Columns("a")) - 1
Range("g3").Value = WorksheetFunction.Sum(Plan1.Columns("b"))
Range("h3").Value = WorksheetFunction.Sum(Plan1.Columns("c"))

End Sub