Tempo de leitura: 3 minutos
Macro do Aplicativo Microsoft Excel VBA, calcula folha de pagamento salario liquido a receber, descontando vale transporte, faltas, adiantamentos, inss, imposto de renda com base tabela desconto, inss, salario família assistência média hospitalar. Planilha exemplo realizado para treinamentos com macros e fórmulas MS Excel VBA. A planilha para uso fora do treinamento tem ser revisada.
PLANILHA FOLHA DE PAGAMENTO desenvolvida com Fórmulas e Excel VBA
Membros, baixe a planiha na Categoria
SBI – Planilhas Inteligentes
Sub sbx_calcula_salario()
Dim i As Long
Dim tSoma As Double
For i = 6 To Cells(Rows.Count, “c”).End(xlUp).Row
‘calcula salário base
Cells(i, “e”).Value = Cells(i, “d”).Value * 30
If Cells(i, “i”).Value = 0 Then
Cells(i, “g”).Value = Cells(i, “f”).Value
Else
Cells(i, “g”).Value = Cells(i, “e”).Value – Cells(i, “d”).Value * Cells(i, “i”).Value
End If
Cells(i, “j”).Value = (Cells(i, “h”).Value * 0.4)
Cells(i, “j”).NumberFormat = “##,##0.00”
‘//=======’compara valores com a tabela de aliquota do INSS
For vBusca = 29 To 32
If Cells(i, “g”).Value >= Cells(vBusca, “a”) And _
Cells(i, “g”) <= Cells(vBusca + 1, “a”) Then
Cells(i, “l”).Value = Cells(i, “g”).Value * Cells(vBusca, “b”)
ElseIf Cells(i, “g”).Value >= Cells(vBusca + 1, “a”) And _
Cells(i, “g”) <= Cells(vBusca + 2, “a”) Then
Cells(i, “l”).Value = Cells(i, “g”).Value * Cells(vBusca + 1, “b”)
Exit For
ElseIf Cells(i, “g”).Value >= Cells(vBusca + 2, “a”) And _
Cells(i, “g”) <= Cells(vBusca + 3, “a”) Then
Cells(i, “l”).Value = Cells(i, “g”).Value * Cells(vBusca + 2, “b”)
Exit For
Else
Cells(i, “l”).Value = Cells(i, “g”).Value * Cells(vBusca + 3, “b”)
Exit For
End If
Next vBusca
‘//=======’calcular salário familia
If Cells(i, “g”).Value > Cells(29, “a”) Then
Cells(i, “n”).Value = (Cells(i, “b”).Value * 0.83)
Else
Cells(i, “n”).Value = (Cells(i, “b”).Value * 6.66)
End If
‘//=======’calcular imposto de renda
If Cells(i, “g”).Value >= 1800# Then
Cells(i, “p”).Value = 315
Cells(i, “p”).NumberFormat = “##,##0.00”
ElseIf Cells(i, “g”).Value > 900# Then
Cells(i, “p”).Value = 135
Cells(i, “p”).NumberFormat = “##,##0.00”
Else
Cells(i, “p”).Value = “Isento”
Cells(i, “p”).Font.ColorIndex = 3
End If
‘//=======’calcular Vale Transporte
If Cells(i, “g”).Value <= 834.5 Then
Cells(i, “r”).Value = Cells(i, “g”) * 0.06
Else
Cells(i, “r”).Value = 50#
End If
‘//=======’ calculo vale refeição
If Cells(i, “g”).Value >= 1000# Then
Cells(i, “t”).Value = 100#
Else
Cells(i, “t”).Value = Cells(i, “g”).Value * 0.1
End If
‘//===========’salario a receber
Cells(i, “v”).Value = Cells(i, “g”).Value * 0.06
Cells(i, “y”).Value = Cells(i, “g”).Value + _
Cells(i, “n”).Value – _
Cells(i, “j”).Value – _
Cells(i, “L”).Value – _
Cells(i, “r”).Value – _
Cells(i, “t”).Value – _
Cells(i, “v”).Value + _
Cells(i, “x”).Value
Next i
‘//==============’for aninhado para percorrer todas a linhas e coluna
‘específicas e somar os valores
For J = 5 To 25 Step 2
For vlin = 6 To Cells(Rows.Count, “c”).End(xlUp).Row
If J = 9 Then J = 10
If J = 24 Then J = 25
If IsNumeric(Cells(vlin, J)) Then
tSoma = tSoma + Cells(vlin, J)
End If
Next vlin
Cells(vlin + 1, J).Value = tSoma ‘descarregar os valores totais..
tSoma = 0 ‘zerando a variável tSoma para a proxima somar proxima coluna
Next J
End Sub
Sub sbx_limpar_teste()
Dim i As Long
ul = Cells(Rows.Count, “c”).End(xlUp).Row + 1
Range(Cells(6, “e”), Cells(ul + 2, “e”)).ClearContents
Range(Cells(6, “g”), Cells(ul + 2, “g”)).ClearContents
Range(Cells(6, “j”), Cells(ul + 2, “j”)).ClearContents
Range(Cells(6, “l”), Cells(ul + 2, “l”)).ClearContents
Range(Cells(6, “n”), Cells(ul + 2, “n”)).ClearContents
Range(Cells(6, “p”), Cells(ul + 2, “p”)).ClearContents
Range(Cells(6, “r”), Cells(ul + 2, “r”)).ClearContents
Range(Cells(6, “t”), Cells(ul + 2, “t”)).ClearContents
Range(Cells(6, “v”), Cells(ul + 2, “v”)).ClearContents
Range(Cells(6, “y”), Cells(ul + 2, “y”)).ClearContents
MsgBox “dados foram limpos para o teste”, vbInformation, “Escola Saberexcel VBA Estudos®”
End Sub
Sub sbx_mensagem()
MsgBox (“Para limpar os dados para o teste clique na vassourinha”), vbCritical, “Escola Saberexcel VBA Estudos®”
End Sub
Faça o Download do exemplo da folha de planilha
Folha-de-Pagamento-Excel-VBA-Exercicio.zip (283 downloads)