Ejemplos de macros Excel VBA Ponemos a tu disposición una lista de ejemplos de macros personales de Excel que pueden se
Views 222 Downloads 6 File size 100KB
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 Then Selection.HorizontalAlignment = xlLeft Else Selection.HorizontalAlignment = xlRight End If End Sub
Convertir pesetas a euro Sub Convertir() Set Area = Selection For Each Cell In Area z = Round(Cell / 166.386, 2) Cell.Value = z Cell.NumberFormat = "#,##0.00" Next Cell End Sub
Pegar formato Sub PegarFormato() Selection.PasteSpecial Paste:=xlFormats Application.CutCopyMode = False End Sub
Pegar valor Sub PegarValor() Selection.PasteSpecial Paste:=xlValues Application.CutCopyMode = False End Sub
Dos decimales Sub DosDec() Dim Area As Range Set Area = Selection For Each Cell In Area z = Round(Cell, 2) Cell.Value = z Cell.NumberFormat = "#,##0.00" Next Cell End Sub
Separador de miles Sub SeparadorMil() Dim Area As Range Set Area = SelectionIf Area.NumberFormat = "#,##0" Then Area.NumberFormat = "#,##0.00" Else Selection.NumberFormat = "#,##0" End If End Sub
Suprimir filas vacías Sub SuprimirFilasVacias() LastRow = ActiveSheet.UsedRange.Row - 1 + _ ActiveSheet.UsedRange.Rows.Count For r = LastRow To 1 Step -1 If Application.CountA(Rows(r)) = 0 Then Rows(r).Delete End If Next r End Sub
Autofilter Sub FilterExcel() Selection.AutoFilter End Sub
Grids (Líneas de división) Sub Grids() If ActiveWindow.DisplayGridlines = True Then ActiveWindow.DisplayGridlines = False Else
ActiveWindow.DisplayGridlines = True End If End Sub
Cambiar A1 a RC (columnas tiene números en vez de letras) Sub Rc() If Application.ReferenceStyle = xlR1C1 Then Application.ReferenceStyle = xlA1 Else Application.ReferenceStyle = xlR1C1 End If End Sub
Modificar paleta de colores Sub ModificarPaleta() ActiveWindow.Zoom = 75 ActiveWorkbook.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 = Worksheets For Each wsHoja In ActiveWorkbook.Worksheets If wsHoja.Visible = False Then wsHoja.Visible = True End If Next wsHoja End Sub