Aprenda Excel VBA Microsoft
Excel VBA Macros Funcoes
Extração de número de Excel VBA - Extração de número de loto , loteria
‘=AleatórioLoto(1;49;6)
Function AleatorioLoto(Botao As Integer, Top As Integer, Amount As Integer)
Dim iNum As String
Dim strNum As String
Dim i As Integer
Application.Volatile
iNum = Int((Top - Botao + 1) * Rnd + Botao)
For i = 1 To Amount
strNum = Trim(strNum & ” ” & iNum)
Do Until InStr(1, strNum, iNum) = 0
iNum = Int((Top - Botao + 1) * Rnd + Botao)
Loop
Next i
AleatorioLoto = strNum
End Function
‘———————————–‘http://www.saberexcel.com O site das 15.000 Macros, funcoes e formulas, planilhas, downloads, apostilas
Excel VBA Funcoes Formulas
Loto - extrai seis números aleatórios na planilha
ligar a macro e acioná-la.
‘Esta macro extrai 6 números aleatórios
Sub Loto()
Dim i, num, bolas(49)
For i = 1 To 49
bolas(i) = i
Next
Randomize Timer
For i = 1 To 6
num = 1 + Int((Rnd * (49 - i)))
ActiveCell.Offset(0, i - 1).Value = bolas(num)
bolas(num) = bolas(50 - i)
Next
End Sub
‘—‘
Site das Macros Excel VBA
( 15.000 Macros, Funções, Fórmulas, Blog, Apostilas, Dicas, Boletins, 5.000 Planilhas Modelos)http://www.saberexcel.com/
Excel VBA Macros Planilhas Funcoes e ´Formulas
Loto - extrai seis números aleatórios10 de Julho, 2008
‘Esta macro extrai 6 números aleatórios somente ate 49
Sub Loto()
Dim i, choice, bolas(49)
For i = 1 To 49
bolas(i) = i
Next
Randomize Timer
For i = 1 To 6
choice = 1 + Int((Rnd * (49 - i)))
ActiveCell.Offset(0, i - 1).Value = bolas(choice)
bolas(choice) = bolas(50 - i)
Next
End Sub
‘—‘
Site das Macros Excel VBA
( 15.000 Macros, Funções, Fórmulas, Blog, Apostilas, Dicas, Boletins, 5.000 Planilhas Modelos)
http://www.saberexcel.com/
' Excel VBA Macros (aplicativo ms excel )
' Esta macro insere hiperlink na planilha um para navegar para outras planilhas.
Sub Hyperlink_navegar_planilhas()
Dim i As Integer
For i = 1 To Worksheets.Count
With Sheets(”Plan1″)
.Cells(i, 1).Value = Worksheets(i).Name
.Cells(i, 1).Hyperlinks.Add Anchor:=.Cells(i, 1), _
Address:=”", SubAddress:=.Cells(i, 1) & “!A1″
End With
Next i
End Sub
’—‘
Site das Macros Excel VBA
( 25.000 Macros, Funções, Fórmulas, Blog, Apostilas, Dicas, Boletins, 5.000 Planilhas Modelos)
http://www.saberexcel.com.br/‘—————————————–‘
Option Explicit
‘Excel VBA - insere formatação na célula onde há zero,
‘por exemplo: celula B5 = 0, acionar a macro: B5 = 0,00
‘primeiramente cor azul, posteriormente cor amarela.
Sub Insere_formatacao_no_zero()
Dim Cel As Range, texto As Variant
For Each Cel In Selection
If Left(Cel.NumberFormat, 2) <> “;;” Then
Cel.NumberFormat = “;;” & “”"” & Cel & “”"”
Cel.Value = 0
‘Indica “Especial” celulas com determinado formato
Cel.Interior.ColorIndex = 34
Else
texto = Split(Cel.NumberFormat, “;”)
Cel.NumberFormat = “#,##0.00″
Cel.Value = Mid(texto(2), 2, Len(texto(2)) - 2)
‘muda a cor da formatação
Cel.Interior.ColorIndex = 6
End If Next
End Sub
'.....................'
Site das macros http://www.saberexcel.com Coleção de 15.000 macros, funções e fórmulas