VBA Tipos de Datos Valores por DefectoTipo de Dato Espacio en Memoria en Bytes Rango de Valores
Boolean 2 True o FalseInteger 2 -32,768 a 32,767Long 4 -2,147,483,648 a 2,147,483,647Single 4 -3.402823E38 a 1.401298E45Double 8 -1.8E308 a 1,8E308Currency 8 -922,337,203,685,477.588 a 922,337,203,685,477.588
Date 8 1/ 1/ 100 - 12/ 31/ 9999String 1 por Carácter VariabeObject 4Variant Variable
User Defined Variable Variable
https://es.scribd.com/doc/138212335/Pedro-Lopez-Salazar-Excel-Avanzado-Extremo-2013
https://books.google.com.pe/books?id=-BgTLQOCIgkC&pg=RA7-PT65&lpg=RA7-PT65&dq=asumir+valores+con+vba+excel&source=bl&ots=79zNFXryfV&sig=D1LVsBEFVNpnNOYWUDg7MfETkb8&hl=es&sa=X&ved=0ahUKEwjwkdC9mtDJAhUMJCYKHYYgCHsQ6AEIGjAA#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-CON-CARGA-BIAXIAL
https://www.youtube.com/watch?v=vP40SnKdAaM&index=45&list=PLFNWPvtjBMjtnYLCp8KJwD1Ref7WLCIVZ
Típicamente 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 solución, es decir un valor que satisfaga la celda objetivo.Si tenemos una celda objetivo la cual depende de dos o más 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 solución de la ecuación:
Ecuación 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 raíces, vamos a realizar una gráfica de la ecuación anterior, pero antes vamos a desarrollar la ecuación, para ponerla en una forma polinomial igualada a cero.Efectuando operaciones algebraicas sobre la ecuación anterior, esta ecuación se
puede expresar de la manera siguiente:
Ecuación 2
https://www.youtube.com/watch?v=E62yBQGubW8
https://tecdigital.tec.ac.cr/revistamatematica/cursos-linea/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 módulo del Explorador de proyectos del Editor de VBA el siguiente código, formando nuestra macro de Excel:
view plain print ?
1. Sub ExportarImagen() 2. Dim img As Shape 3. 4. Application.ScreenUpdating = False 5. For Each img In ActiveSheet.Shapes 6. 'añadimos un gráfico 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 tamaño de imagen y gráfico 14. With img 15. chrt.Width = .Width 16. chrt.Height = .Height 17. 'copiamos la imagen 18. .Copy 19. End With 20. 'pegamos dentro del gráfico la imegen 21. ActiveChart.Paste 22. 'exportamos el gráfico 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 raíces son imagináreas"
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. TextBox4.Text = "Tiene raices imaginarias" 12. 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. Trim(X1) + " X2 = " + Trim(X2) 17. End If 18. Else 19. 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-formulas-personalizadas/
https://books.google.com.pe/books?id=XS2g1lK-jOsC&pg=PA5&lpg=PA5&dq=formula+general+en+vba+excel&source=bl&ots=Yav_weSONS&sig=1a6f6vriUPOQM15G3MZCwYIlPlM&hl=es&sa=X&ved=0ahUKEwiI95rBi8bJAhUK8CYKHQwLDZUQ6AEIMjAF#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 SubNow, 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 código a crear sería 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 = "Solución 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