ejemplos de macros excel vba
Post on 08-Apr-2015
408 Views
Preview:
TRANSCRIPT
Ejemplos de macros Excel VBA
Ponemos a tu disposición una lista de ejemplos de macros personales de Excel que pueden ser útiles en tu trabajo diario. Recordamos que las macros Excel VBA ofrecen infinidad de posibilidades – trata de encontrar las tareas repititivas y de ahí crear las macros.
Unos ejemplos de aplicaciones de macros Excel VBA: Cambiar propiedades de las hojas Excel, suprimir filas, aplicar los formatos más comúnes… En poco tiempo tendrás unas macros imprescindibles, y ya no podrás trabajar en Excel sin ellas.
Grabar y programar macros de Excel es una estupenda (posiblemente la mejor) manera de empezar a aprender Visual Basic para Excel (VBA).
Para ayuda sobre como se graban las macros, ver Grabar una macro.
Alineación izquierda/derecha
Sub Ajustar_izq_der()If Selection.HorizontalAlignment = xlRight ThenSelection.HorizontalAlignment = xlLeftElseSelection.HorizontalAlignment = xlRightEnd IfEnd Sub
Convertir pesetas a euro
Sub Convertir()Set Area = SelectionFor Each Cell In Areaz = Round(Cell / 166.386, 2)Cell.Value = zCell.NumberFormat = "#,##0.00"Next CellEnd Sub
Pegar formato
Sub PegarFormato()Selection.PasteSpecial Paste:=xlFormatsApplication.CutCopyMode = False
End Sub
Pegar valor
Sub PegarValor()Selection.PasteSpecial Paste:=xlValuesApplication.CutCopyMode = FalseEnd Sub
Dos decimales
Sub DosDec()Dim Area As RangeSet Area = SelectionFor Each Cell In Areaz = Round(Cell, 2)Cell.Value = zCell.NumberFormat = "#,##0.00"Next CellEnd Sub
Separador de miles
Sub SeparadorMil()Dim Area As RangeSet Area = SelectionIf Area.NumberFormat = "#,##0" ThenArea.NumberFormat = "#,##0.00"ElseSelection.NumberFormat = "#,##0"End IfEnd Sub
Suprimir filas vacías
Sub SuprimirFilasVacias()LastRow = ActiveSheet.UsedRange.Row - 1 + _ActiveSheet.UsedRange.Rows.CountFor r = LastRow To 1 Step -1If Application.CountA(Rows(r)) = 0 ThenRows(r).DeleteEnd IfNext rEnd Sub
Autofilter
Sub FilterExcel()Selection.AutoFilterEnd Sub
Grids (Líneas de división)
Sub Grids()
If ActiveWindow.DisplayGridlines = True ThenActiveWindow.DisplayGridlines = FalseElseActiveWindow.DisplayGridlines = TrueEnd IfEnd Sub
Cambiar A1 a RC (columnas tiene números en vez de letras)
Sub Rc()If Application.ReferenceStyle = xlR1C1 ThenApplication.ReferenceStyle = xlA1ElseApplication.ReferenceStyle = xlR1C1End IfEnd Sub
Modificar paleta de colores
Sub ModificarPaleta()ActiveWindow.Zoom = 75ActiveWorkbook.Colors(44) = RGB(236, 235, 194)ActiveWorkbook.Colors(40) = RGB(234, 234, 234)ActiveWorkbook.Colors(44) = RGB(236, 235, 194)End Sub
Mostrar todas las hojas
Sub MostrarHojas()Set wsHoja = WorksheetsFor Each wsHoja In ActiveWorkbook.WorksheetsIf wsHoja.Visible = False ThenwsHoja.Visible = TrueEnd IfNext wsHojaEnd Sub
top related