You are on page 1of 25

https://es.scribd.

com/doc/138212335/Pedro-Lopez-Salazar-Excel-AvanzadoExtremo-2013

https://books.google.com.pe/books?id=-BgTLQOCIgkC&pg=RA7PT65&lpg=RA7PT65&dq=asumir+valores+con+vba+excel&source=bl&ots=79zNFXryfV&sig=
D1LVsBEFVNpnNOYWUDg7MfETkb8&hl=es&sa=X&ved=0ahUKEwjwkdC9mtDJA
hUMJCYKHYYgCHsQ6AEIGjAA#v=onepage&q=asumir%20valores%20con
%20vba%20excel&f=false
http://www.corazondejesusza.net/apuntes/Visual%20Basic.htm
http://www.corazondejesusza.net/apuntes/Visual
%20Basic.htm#_Toc145227688
https://es.scribd.com/doc/51617642/DISENO-DE-ZAPATAS-AISLADAS-CONCARGA-BIAXIAL
https://www.youtube.com/watch?
v=vP40SnKdAaM&index=45&list=PLFNWPvtjBMjtnYLCp8KJwD1Ref7WLCIVZ

Tpicamente cada hoja de Excel le permite cambiar el valor de una celda y ver cual es el efecto en las
celdas dependientes. Con Goal Seek (Buscar Objetivo) de Excel del men Tools (Herramientas)
podemos revertir este proceso. Con Goal Seek, usted puede encontrar que valor debe tener una
celda, para que una celda dependiente de sta, tenga un valor objetivo determinado.
Goal Seek trabaja nicamente con dos celdas, la celda objetivo y otra celda de la cual depende la
celda objetivo y a la cual Goal Seek cambiar los valores hasta encontrar una solucin, es decir un
valor que satisfaga la celda objetivo.
Si tenemos una celda objetivo la cual depende de dos o ms celdas, no podemos aplicar Goal Seek,
debemos utilizar el add-in Solver, el cual se ha tratado en anteriores post.
Ejemplo:
Si deseamos encontrar la solucin de la ecuacin:

Ecuacin 1
Lo podemos hacer mediante el comando de Goal Seek (Buscar Objetivo) del men Tools
(Herramientas).
Para darnos una idea de donde se encuentran aproximadamente las races, vamos a realizar una
grfica de la ecuacin anterior, pero antes vamos a desarrollar la ecuacin, para ponerla en una
forma polinomial igualada a cero.
Efectuando operaciones algebraicas sobre la ecuacin anterior, esta ecuacin se puede expresar de

la manera siguiente:

Ecuacin 2

https://www.youtube.com/watch?v=E62yBQGubW8
https://tecdigital.tec.ac.cr/revistamatematica/cursoslinea/NUMERICO/excel/VBAExcel-MNumericos.pdf
http://www.academia.edu/5853969/Programaci
%C3%B3n_Visual_Basic_VBA_para_Excel_y_An%C3%A1lisis_Num
%C3%A9rico_Contents
http://html.rincondelvago.com/fundamentos-de-programacion_8.html
http://www.academia.edu/5087949/_Secretos_de_Excel
http://www.nachocabanes.com/tutors/cupas1.htm
http://es.slideshare.net/carlospardo01/excel-revelado
Insertaremos en un mdulo del Explorador de proyectos del Editor de VBA el siguiente cdigo,
formando nuestra macro de Excel:
view plainprint?

1.

Sub ExportarImagen()

2.

Dim img As Shape

3.
4.

Application.ScreenUpdating = False

5.

For Each img In ActiveSheet.Shapes

6.

'aadimos un grfico

7.

Charts.Add

8.

'lo situamos como objeto en la Hoja 3

9.

ActiveChart.Location Where:=xlLocationAsObject, Name:="Hoja1"

10. Set chrt = ActiveSheet.ChartObjects(1)


11.

12.

nombreimg = img.Name

13.

'adaptamos tamao de imagen y grfico

14.

With img

15.

chrt.Width = .Width

16.

chrt.Height = .Height

17.

'copiamos la imagen

18.

.Copy

19.

End With

20.

'pegamos dentro del grfico la imegen

21.

ActiveChart.Paste

22.

'exportamos el grfico con el nombre del objeto (imagen)

23.

chrt.Chart.Export Filename:="C:\" & nombreimg & ".gif"

24. chrt.Delete
25. Next img
26.
27. Application.ScreenUpdating = True
28. End Sub

Function FRaiz1(a, b, c)
If (b * b - 4 * a * c < 0) Then
MsgBox "Las races son imaginreas"
Return
Else
FRaiz1 = (-b + Sqr(b * b - 4 * a * c)) / (2 * a)
End If
End Function
1.

Public Class Form1

2.

Private Sub Button1_Click(ByVal sender As System.Object,

3.

ByVal e As System.EventArgs) Handles Button1.Click

4.

Dim disc, a, b, c, X1, X2 As Double

5.

a = TextBox1.Text

6.

b = TextBox2.Text

7.

c = TextBox3.Text

8.

disc = Math.Pow(b, 2) - 4 * a * c

9.

If (a <> 0) Then

10.

If ((disc) < 0) Then

11.
12.

TextBox4.Text = "Tiene raices imaginarias"


Else

13.

X1 = (-b + (Math.Sqrt(disc))) / (2 * a)

14.

X2 = (-b - (Math.Sqrt(disc))) / (2 * a)

15.

TextBox4.Text = "La raices son X1 = " +

16.
17.
18.
19.

Trim(X1) + " X2 = " + Trim(X2)


End If
Else
TextBox4.Text =

20.

"coeficiente cuadratico debe ser diferente de cero"

21.

End If

22.

End Sub

23. End Class

http://excel.facilparami.com/2012/06/vba-crear-funciones-formulaspersonalizadas/
https://books.google.com.pe/books?id=XS2g1lKjOsC&pg=PA5&lpg=PA5&dq=formula+general+en+vba+excel&source=bl&ots
=Yav_weSONS&sig=1a6f6vriUPOQM15G3MZCwYIlPlM&hl=es&sa=X&ved=0ahU
KEwiI95rBi8bJAhUK8CYKHQwLDZUQ6AEIMjAF#v=onepage&q=formula
%20general%20en%20vba%20excel&f=false
Range("H2", Range("H20000").End(xlUp)).NumberFormat = "General"
Range("G2", Range("G20000").End(xlUp)).NumberFormat = "General"
Sub GeneralFormatForAllPopulatedCells()
Dim wb As Workbook
Dim ws As Worksheet
Dim g As Long, h As Long
Dim lastRow As Long
Dim rng As Range
Set wb = ThisWorkbook
Set ws = wb.Sheets("Sheet2")
g = ws.Range("G" & ws.Rows.Count).End(xlUp).Row
h = ws.Range("H" & ws.Rows.Count).End(xlUp).Row
If g > h Then
lastRow = g
Else
lastRow = h
End If
Set rng = ws.Range("G1:H" & lastRow)
rng.NumberFormat = "General"

End Sub

Now, what if I don't know the cell whose number I want to round? In other words, i
have an integer variable in my code, N, that can take on multiple values, and I want to
round the number in row number N of column B.
How do I write this? I tried:
Range("A1").Formula = "=10*Round(B" & N & " & "/10",0)"

But this doesn't work. Tried multiple layouts for the quotes but without success.
Can anyone let me know:
1.

How to enter that simple formula? and more importantly

2.

Provide some link/reference that would help me with entering other formulas in
the future?
Thanks
El cdigo a crear sera el siguiente:
Function ecuacion(ByRef a, ByRef b, ByRef c) As String
Dim raiz As Double
Dim X1 As Long, X2 As Long
raiz = (b * b) - 4 * a * c
If raiz > 0 Then
X1 = (-b + Sqr(raiz)) / 2 * a
X2 = (-b - Sqr(raiz)) / 2 * a
ecuacion = "X1 = " & X1 & " ;X2 =" & X2
ElseIf raiz = 0 Then
X1 = -b / 2 * a
X2 = X1
ecuacion = "X1 = " & X1 & " ;X2 =" & X2
ElseIf raiz <>

ecuacion = "Solucin Indefinida"


End If
End Function

Private Sub codigo_Change()


Range("A6").Select
ActiveCell.FormulaR1C1 = codigo

End Sub

Private Sub descripcion_Change()

Range("B6").Select
ActiveCell.FormulaR1C1 = descripcion

End Sub
Private Sub vlr_unit_Change()
Range("C6").Select
ActiveCell.FormulaR1C1 = vlr.unit

End Sub

Private Sub cantidad_Change()


Range("D6").Select
ActiveCell.FormulaR1C1 = cantidad
total = Val(VLR_UNIT) * Val(cantidad)

End Sub
Private Sub total_Change()
Range("E6").Select
ActiveCell.FormulaR1C1 = total

End Sub

Private Sub UserForm_Click()

End Sub

You might also like