0% found this document useful (0 votes)
15 views

Formulas Excel Con Macros

The document describes several modules that automate tasks related to invoices and lists. Module 1 resets a cell value. Module 2 prints a range. Module 3 includes functions to write out numbers as words in Spanish. Module 4 handles adding new records. Module 5 allows modifying existing records. Module 6 saves invoices to files. Module 7 is empty. Module 8 prints, clears cells, and increments an invoice number.

Uploaded by

luisarroyave2024
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Formulas Excel Con Macros

The document describes several modules that automate tasks related to invoices and lists. Module 1 resets a cell value. Module 2 prints a range. Module 3 includes functions to write out numbers as words in Spanish. Module 4 handles adding new records. Module 5 allows modifying existing records. Module 6 saves invoices to files. Module 7 is empty. Module 8 prints, clears cells, and increments an invoice number.

Uploaded by

luisarroyave2024
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 6

MODULO 1 (BAJA)

Sub Baja()
'
' Baja Macro
' Macro grabada el 28/09/2006 por Windows
'
' Acceso directo: CTRL+x
'
Range("D22").Select
ActiveCell.FormulaR1C1 = ""
Sheets("Listado").Select
ActiveSheet.Unprotect
Range("J6").Select
Valor = ActiveCell.Value
Range("C7").Select
While ActiveCell.Value <> ""
If ActiveCell.Value <> Valor Then
ActiveCell.Offset(1, 0).Select
Else
Sheets("Altas").Select
Range("H22:J22").Select
Selection.Copy
Sheets("Listado").Select
ActiveSheet.Paste
Range("C7:E1006").Select
Application.CutCopyMode = False
Selection.Sort Key1:=Range("C7"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("C7:E1006").Select
Selection.Locked = True
Selection.FormulaHidden = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Sheets("Altas").Select
Range("D22").Select
ActiveCell.FormulaR1C1 = "BORRADO"
End If
Wend
Sheets("Listado").Select
ActiveSheet.Protect
Sheets("Altas").Select
Range("D22").Select
If ActiveCell.Value <> "BORRADO" Then
Range("D22").Select
ActiveCell.FormulaR1C1 = "NO EXISTE"
End If

End Sub

MODULO 2 (IMPRIMIR)
Sub Imprimir()
'
' Imprimir Macro
' Macro grabada el 28/09/2006 por Windows
'
' Acceso directo: CTRL+i
'
Sheets("Listado").Select
ActiveSheet.Unprotect
Range("C7:E1006").Select
Application.CutCopyMode = False
Selection.Sort Key1:=Range("C7"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("E1007").Select
Selection.End(xlUp).Select
Range(Selection, Selection.End(xlToLeft)).Select
Range(Selection, Selection.End(xlUp)).Select

Selection.PrintOut Copies:=1, Collate:=True


ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True

End Sub

MODULO 3 (NUMEROS - LETRAS)

Option Explicit
'Función programada inicialmente por Héctor Miguel (un gran experto en la materia)

Function EnLetras(Valor, Optional ByVal Tipo As Byte = 1) As String 'funcion Principal '
If Not IsNumeric(Valor) Then
EnLetras = "¡ La referencia no es valor o... 'excede' la precisión !!!":
Exit Function
End If: Dim Moneda As String, Fracs As String, Cents As Integer
If Int(Abs(Valor)) = 1 Then Moneda = " euro" Else Moneda = " euros"
If Right(Letras(Abs(Int(Valor))), 6) = "illón " Or _
Right(Letras(Abs(Int(Valor))), 8) = "illones " Then Moneda = "de" & Moneda
Cents = Application.Round(Abs(Valor) - Int(Abs(Valor)), 2) * 100
If Cents = 1 Then Fracs = " centimo" Else Fracs = " centimos"
If Cents = 0 Then Fracs = "" Else Fracs = " con " & Letras(Cents) & Fracs
EnLetras = Letras(Int(Abs(Valor))) & Moneda & Fracs
If Valor < 0 Then EnLetras = "menos " & EnLetras
If Tipo = 2 Then EnLetras = UCase(EnLetras) ' TODO EN MAYUSCULAS '
If Tipo = 3 Then EnLetras = StrConv(EnLetras, vbProperCase) ' Todo Como Nombre Propio '
If Tipo = 4 Then EnLetras = UCase(Left(EnLetras, 1)) & Mid(EnLetras, 2) 'Primera letra en mayuscula SOLAMENTE '
EnLetras = "(" & EnLetras & ")"
End Function
Private Function Letras(Valor) As String ' Función Auxiliar [uso 'exclusivo'de la funcion 'principal'] '
Select Case Int(Valor)
Case 0: Letras = "cero"
Case 1: Letras = "un"
Case 2: Letras = "dos"
Case 3: Letras = "tres"
Case 4: Letras = "cuatro"
Case 5: Letras = "cinco"
Case 6: Letras = "seis"
Case 7: Letras = "siete"
Case 8: Letras = "ocho"
Case 9: Letras = "nueve"
Case 10: Letras = "diez"
Case 11: Letras = "once"
Case 12: Letras = "doce"
Case 13: Letras = "trece"
Case 14: Letras = "catorce"
Case 15: Letras = "quince"
Case Is < 20: Letras = "dieci" & Letras(Valor - 10)
Case 20: Letras = "veinte"
Case Is < 30: Letras = "veinti" & Letras(Valor - 20)
Case 30: Letras = "treinta"
Case 40: Letras = "cuarenta"
Case 50: Letras = "cincuenta"
Case 60: Letras = "sesenta"
Case 70: Letras = "setenta"
Case 80: Letras = "ochenta"
Case 90: Letras = "noventa"
Case Is < 100: Letras = Letras(Int(Valor \ 10) * 10) & " y " & Letras(Valor Mod 10)
Case 100: Letras = "cien"
Case Is < 200: Letras = "ciento " & Letras(Valor - 100)
Case 200, 300, 400, 600, 800: Letras = Letras(Int(Valor \ 100)) & "cientos"
Case 500: Letras = "quinientos"
Case 700: Letras = "setecientos"
Case 900: Letras = "novecientos"
Case Is < 1000: Letras = Letras(Int(Valor \ 100) * 100) & " " & Letras(Valor Mod 100)
Case 1000: Letras = "mil"
Case Is < 2000: Letras = "mil " & Letras(Valor Mod 1000)
Case Is < 1000000: Letras = Letras(Int(Valor \ 1000)) & " mil"
If Valor Mod 1000 Then Letras = Letras & " " & Letras(Valor Mod 1000)
Case 1000000: Letras = "un millón "
Case Is < 2000000: Letras = "un millón " & Letras(Valor Mod 1000000)
Case Is < 1000000000000#: Letras = Letras(Int(Valor / 1000000)) & " millones "
If (Valor - Int(Valor / 1000000) * 1000000) _
Then Letras = Letras & Letras(Valor - Int(Valor / 1000000) * 1000000)
Case 1000000000000#: Letras = "un billón "
Case Is < 2000000000000#
Letras = "un billón " & Letras(Valor - Int(Valor / 1000000000000#) * 1000000000000#)
Case Else: Letras = Letras(Int(Valor / 1000000000000#)) & " billones "
If (Valor - Int(Valor / 1000000000000#) * 1000000000000#) _
Then Letras = Letras & " " & Letras(Valor - Int(Valor / 1000000000000#) * 1000000000000#)
End Select
End Function

MODULO 4 (ALTAS)

Sub Altas()
'
' Altas Macro
' Macro grabada el 28/09/2006 por Windows
'
' Acceso directo: CTRL+a
'
Sheets("Listado").Select
Range("H6").Select
If ActiveCell.Value = 0 Then
Sheets("Altas").Select
Range("D6").Select
ActiveCell.FormulaR1C1 = "YA EXISTE"
Else
ActiveSheet.Unprotect
Range("C1007").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
Sheets("Altas").Select
Range("C6:E6").Select
Selection.Copy
Sheets("Listado").Select
ActiveSheet.Paste
Range("C7:E1006").Select
Application.CutCopyMode = False
Selection.Sort Key1:=Range("C7"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("C7:E1006").Select
Selection.Locked = True
Selection.FormulaHidden = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Sheets("Altas").Select
Range("C6:E6").Select
Selection.ClearContents
Range("A1").Select
End If
End Sub

MODULO 5 (LISTADOS)

Sub Modificar()
'
' Modificar Macro
' Macro grabada el 28/09/2006 por Windows
'
' Acceso directo: CTRL+m
'
Sheets("Listado").Select
ActiveSheet.Unprotect
Range("I6").Select
Valor = ActiveCell.Value
Range("C7").Select
While ActiveCell.Value <> ""
If ActiveCell.Value <> Valor Then
ActiveCell.Offset(1, 0).Select
Else
Sheets("Altas").Select
Range("C14:E14").Select
Selection.Copy
Sheets("Listado").Select
ActiveSheet.Paste
Range("C7:E1006").Select
Application.CutCopyMode = False
Selection.Sort Key1:=Range("C7"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("C7:E1006").Select
Selection.Locked = True
Selection.FormulaHidden = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Sheets("Altas").Select
Range("C14:E14").Select
Selection.ClearContents
Range("C14").Select
End If
Wend
Sheets("Listado").Select
ActiveSheet.Protect
Sheets("Altas").Select
Range("C14").Select
If ActiveCell.Value <> "" Then
Range("D14").Select
ActiveCell.FormulaR1C1 = "NO EXISTE"
End If

End Sub

MODULO 6 (GUARDAR FACTURA) ---- VER OPCION DE. ¿cómo modificar un módulo?

Range("K11").Select
Application.CutCopyMode = False
With Selection.Validation
.Delete
.Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
:=xlBetween
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = "Seleccione día"
.ErrorMessage = ""
.ShowInput = False
.ShowError = False
End With

NombreArchivo = "C:\FACTUJA\"
'idea del Usuario arperez
NArchivo = Format(Range("K11").Value, "")
ActiveWorkbook.SaveAs NombreArchivo & NArchivo, , , , , , , , , , , False
ActiveWindow.Close
End Sub

MODULO 7
VACIO

MODULO 8 IMPRIMIR - LIMPIAR CONTENIDO Y AÑADIR UN NÚMERO A LA FACTURA)

Sub IMPRIME2()
Application.ScreenUpdating = False
Range("C17:C42").ClearContents
Range("H17:H42").ClearContents
Range("J17:J42").ClearContents
Range("I3:L7").ClearContents
Range("K11") = Range("K11").Value + 1
FormulaR1C1 = "=TODAY()"
Range("K11").Select
Application.ScreenUpdating = True
End Sub

COMO MODIFICAR UN MÓDULO

pulsamos a la vez las teclas Alf + F11 y nos sale la pantalla de Microsof visual Basic ( VER EJEMPLO)
En este ejemplo, que tengo en pantalla, que es el módulo 6 (GUARDAR FACTURA), podremos modificar la ruta donde
se guardarán las facturas en nuestro ordenador.

En este caso yo he creado en el disco C:\ una carpeta llamada FACTUJA, que será donde una vez creada, se guardarán
las facturas.
Esto se puede modificar en función de cada usuario, si un usuario lo quiere guardar en otra carpeta, no hay mas que
ir al modulo correspondiente (en este caso el módulo 6), y modificar donde la ruta "C:\FACTUJA\"

MUY IMPORTANTE, añadir la ruta pero SIN MODIFICAR comillas ( " ) o ( \ ), ya que si se modifica esto dejaría de
funcionar.

You might also like