Olá, estou com um probema em fazer minha rotina VBA funcionar. Quero vincular minha rotina a um botão e que ao clicá-lo realize o seguinte: Insira as informações uma a uma de uma planilha em uma célula que fará os calculos e gerará um resultado, quero pegar esse resultado junto com a informação da outra tabela e colar em uma tabela a parte. Meu problema é que ao clicar neste botão aparentemente passa as informações pela célula mas não atualiza minha planilha, não sei o que está ocorrendo. Sei que é um pouco confuso, disponibilizo aqui a rotina.
Private Sub CommandButton1_Click()
Dim linha As Integer
linha = 3
perfil = Sheets("Perfis lam. gerdau").Cells(4, 1).Value
peso = Sheets("Perfis lam. gerdau").Cells(4, 2).Value
volta:
linha = linha + 1
If Sheets("Perfis lam. gerdau").Cells(linha, 1).Value = "" Then GoTo sai
Sheets("calculo").Cells(5, 8).Value = Sheets("Perfis lam. gerdau").Cells(linha, 1).Value
If Sheets("calculo").Cells(5, 13).Value <= 1 Then
If Sheets("calculo").Cells(5, 13).Value < peso Then
peso = Sheets("calculo").Cells(5, 13).Value
perfil = Sheets("calculo").Cells(5, 8).Value
Else
End If
Else
End If
GoTo volta
sai:
Sheets("calculo").Cells(5, 8).Value = perfil
End Sub
Private Sub CommandButton2_Click()
Call otimizar
End Sub
Private Sub CommandButton3_Click()
End Sub
Sub otimizar()
Dim linha As Integer
Dim linha2 As Integer
linha2 = 5
Sheets("calculo").Range("R7:T1000").ClearContents
linha = 3
perfil = Sheets("Perfis lam. gerdau").Cells(4, 1).Value
peso = Sheets("Perfis lam. gerdau").Cells(4, 2).Value
volta:
linha = linha + 1
If Sheets("Perfis lam. gerdau").Cells(linha, 1).Value = "" Then GoTo sai
Sheets("calculo").Cells(5, 8).Value = Sheets("Perfis lam. gerdau").Cells(linha, 1).Value
If Sheets("calculo").Cells(5, 11).Value <= 1 Then
linha2 = linha2 + 1
Sheets("calculo").Cells(5, 20).Value = "Perfil"
Sheets("calculo").Cells(5, 21).Value = "Peso"
Sheets("calculo").Cells(5, 22).Value = "%"
Sheets("calculo").Cells(linha2, 20).Value = Sheets("calculo").Cells(5, 8).Value
Sheets("calculo").Cells(linha2, 21).Value = Sheets("calculo").Cells(13, 13).Value
Sheets("calculo").Cells(linha2, 22).Value = Sheets("calculo").Cells(5, 13).Value
Else
End If
GoTo volta
sai:
Range("R7:T8735").Select
ActiveWorkbook.Worksheets("calculo").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("calculo").Sort.SortFields.Add Key:= _
Range("S8:S160"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
With ActiveWorkbook.Worksheets("calculo").Sort
.SetRange Range("R7:T160")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("calculo").Cells(5, 8).Value = Sheets("calculo").Cells(6, 20).Value
End Sub
Projeto_tcc_macro_teste.xlsx