Excel insertar fórmula desde vba
Tengo una pequeña tabla en excel, en la que tengo fórmulas pero si las inserto de la manera que la tengo, al crear una nueva fila se desplaza y no modifica la fórmula para que siga calculando, sino que me sale error. Ahí va el código, no le puse al final la macro de insertar celda por que no se como solucionarlo aun. Espero me puedan ayudar. Saludos
Private Sub CommandButton1_Click()
'Empty TextBox
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
TextBox6.Value = ""
TextBox7.Value = ""
TextBox8.Value = ""
TextBox9.Value = ""
TextBox10.Value = ""
TextBox11.Value = ""
TextBox12.Value = ""
TextBox13.Value = ""
'Desmarcar OptionButton
OptionButton1.Value = False
OptionButton2.Value = False
TextBox1.SetFocus
' guardar Macro
ActiveWorkbook.Save
End Sub
Private Sub CommandButton2_Click()
Dim emptyRow As Long
'Make Calculo active
Set h2 = Sheets("Calculo")
h2.Activate
'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) - 1
'Transfer information (peso3c2-talla4d2)
Cells(emptyRow, 1).Value = TextBox1.Value
Cells(emptyRow, 2).Value = TextBox2.Value
Cells(emptyRow, 3).Value = TextBox3.Value
Cells(emptyRow, 4).Value = TextBox4.Value
Cells(emptyRow, 5).Value = "=c2/(d2^2)"
If OptionButton1.Value = True Then Cells(emptyRow, 6).Value = "1"
If OptionButton2.Value = True Then Cells(emptyRow, 6).Value = "2"
'Pliegues cutaneos(g2-02)
Cells(emptyRow, 7).Value = TextBox5.Value
Cells(emptyRow, 8).Value = TextBox6.Value
Cells(emptyRow, 9).Value = TextBox7.Value
Cells(emptyRow, 10).Value = TextBox8.Value
Cells(emptyRow, 11).Value = TextBox9.Value
Cells(emptyRow, 12).Value = TextBox10.Value
Cells(emptyRow, 13).Value = TextBox11.Value
Cells(emptyRow, 14).Value = TextBox12.Value
Cells(emptyRow, 15).Value = TextBox13.Value
Cells(emptyRow, 16).Value = "=h2+i2+j2+k2+l2+m2+n2"
If OptionButton1.Value = True Then Cells(emptyRow, 17).Value = "=(495/(1.112-(0.00043499*P2)+(0.00000055*P2*P2)-(0.00028826*B2))-450)"
If OptionButton2.Value = True Then Cells(emptyRow, 17).Value = "=(495/(1.097-(0.00046971*P2)+(0.00000056*P2*P2)-(0.00012828*B2))-450)"
'Empty TextBox
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
TextBox6.Value = ""
TextBox7.Value = ""
TextBox8.Value = ""
TextBox9.Value = ""
TextBox10.Value = ""
TextBox11.Value = ""
TextBox12.Value = ""
TextBox13.Value = ""
'Desmarcar OptionButton
OptionButton1.Value = False
OptionButton2.Value = False
TextBox1.SetFocus
' guardar Macro
ActiveWorkbook.Save
End Sub
Private Sub CommandButton3_Click()
End
End Sub
Respuesta de Esteban RG
3 respuestas más de otros expertos
Respuesta de James Bond
1
Respuesta de Abraham Valencia
Respuesta de Elsa Matilde

y pot cierto modifique tu macro es demasiado código el que usas, no veo el problema con la fórmula, las inserta bien