Factutacion Codigo Completo

40
CuadroMsgItems - 1 Private Sub CommandButton1_Click() Unload CuadroMsgItems End Sub Private Sub CommandButton2_Click() Unload CuadroMsgItems End End Sub

Transcript of Factutacion Codigo Completo

Page 1: Factutacion Codigo Completo

CuadroMsgItems - 1 Private Sub CommandButton1_Click()Unload CuadroMsgItemsEnd Sub

Private Sub CommandButton2_Click()Unload CuadroMsgItemsEndEnd Sub

Page 2: Factutacion Codigo Completo

Hoja1 - 1 Private Sub CommandButton1_Click()IR_A_INICIOEnd Sub

Page 3: Factutacion Codigo Completo

Hoja11 - 1 Private Sub CommandButton1_Click()

Range("G6:G10").ClearContents Range("D6:D10").ClearContents Range("B14:F36").ClearContents Range("G4").Select End Sub

Private Sub CommandButton2_Click()IR_A_INICIOEnd Sub

Private Sub Worksheet_Activate()ScrollArea = "a1:h44"End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Range("g7") = "" Then Range("g7").Value = "Click para rellenar" Range("G7").Interior.Color = &H80FF80 Else Range("G7").Interior.Color = vbWhite End If

If Not Application.Intersect(Target, Range("B14:B36")) Is Nothing Then lanza_facturables_presupuesto End If

If Not Application.Intersect(Target, Range("G7")) Is Nothing Then UserForm7.Show End If

Sheets("Presupuesto (2)").Activate

End Sub

Page 4: Factutacion Codigo Completo

Hoja4 - 1 Private Sub CommandButton1_Click()IR_A_INICIOEnd Sub

Page 5: Factutacion Codigo Completo

Hoja5 - 1 Private Sub CommandButton1_Click()IR_A_INICIOEnd Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub

Page 6: Factutacion Codigo Completo

Hoja6 - 1 Private Sub CommandButton1_Click()IR_A_INICIOEnd Sub

Private Sub CommandButton2_Click()BorrarAlbarancondowhileEnd Sub

Private Sub Label1_Click()If Range("F4") = "A" Then GeneralbaranElse GenerafactinmediataEnd IfEnd Sub

Private Sub Label2_Click()UserForm8.ShowSheets("Albaran").ActivateEnd Sub

Private Sub ToggleButton1_Click()

Application.ScreenUpdating = False

If ToggleButton1.Value = True Then Range("B2") = "Factura" Range("E3") = "Nº Factura" Range("E54") = "Suma Factura" Rows("55:56").EntireRow.Hidden = False Label1.Caption = "GENERAR FACTURA"Else Range("B2") = "Albarán" Range("E3") = "Nº Albarán" Range("E54") = "Suma Albarán" Rows("55:56").EntireRow.Hidden = True Label1.Caption = "GENERAR ALBARAN" End If

End Sub

Private Sub Worksheet_Activate()ScrollArea = "a1:h69"End Sub

Private Sub Worksheet_Change(ByVal Target As Range) 'If Not Application.Intersect(Target, Range("G7")) Is Nothing Then 'Range("A1").Value = Range("A1").Value + 1'End IfEnd Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Application.Intersect(Target, Range("B14:B36")) Is Nothing Then

Page 7: Factutacion Codigo Completo

Hoja6 - 2 lanza_facturables_albaran End If If Range("g7") = "" Then Range("g7").Value = "Click para rellenar" Range("G7").Interior.Color = &H80FF80 Else Range("G7").Interior.Color = vbWhite End If If Not Application.Intersect(Target, Range("G7")) Is Nothing Then UserForm9.Show End If Sheets("Albaran").Select End Sub

Page 8: Factutacion Codigo Completo

Hoja7 - 1 Private Sub CommandButton1_Click()IR_A_INICIOEnd Sub

Page 9: Factutacion Codigo Completo

Macros_Almacen - 1 Sub Botón_Borrar_Albaran()

Application.ScreenUpdating = FalseSheets("Albaran").Select items = Range("C54")Range("C14").Activate

If Range("C14") = "" Then GoTo borranombreEnd If

For b = 1 To items

hoja = ActiveCell.Offset(0, -1) modelo = ActiveCell cantidad = ActiveCell.Offset(0, 2) Sheets(hoja).Select Range("A1").Select Cells.Find(what:=modelo, After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False).Activate ActiveCell.Offset(0, 3).Value = ActiveCell.Offset(0, 3).Value + cantidad Sheets("Albaran").Select ActiveCell.Offset(1, 0).Select

Next b Range("B14:F52").ClearContents borranombre: Range("G5:G11").ClearContents Range("A1").ActivateEnd Sub

Sub IR_A_INICIO()Sheets("INICIO").ActivateEnd Sub

Sub IR_A_ALBARAN()Sheets("Albaran").ActivateEnd Sub

Sub IR_A_FACT()Sheets("Facturacion").ActivateEnd Sub

Sub IR_A_FACTEMIT()Sheets("Facturas emitidas").ActivateEnd Sub

Sub Muestra_User8()UserForm8.Show

Page 10: Factutacion Codigo Completo

Macros_Almacen - 2 End Sub

Sub mUESTRAuSER1()UserForm1.ShowEnd Sub

Sub actualiza_existencias()

'If MsgBox("Asegúrese de que:" + Chr(13) + _'"El Archivo de actualización tiene el mismo nombre que" + Chr(13) + _'"la hoja de la marca." + Chr(13) + _'"Ejemplo:Hoja de marca MRK; nombre del libro:MRK.xlsx" + Chr(13) + Chr(13) + _'"RENOMBRELO SI ES PRECISO." + Chr(13) + _'"¿Es esto correcto?", vbYesNo) = vbNo Then Exit Sub

Application.ScreenUpdating = False

'nlib = InputBox("Nombre del libro.....")nlib = UserForm5.ComboBox1LIBRO = nlib & (".xlsx")ruta = ThisWorkbook.Path & "\Pedidos Recibidos\"

Workbooks.Open Filename:=ruta & LIBRO Workbooks(LIBRO).Activate Sheets("Hoja1").Range("A2").Select Do While ActiveCell <> "" modelo = ActiveCell cantidad = ActiveCell.Offset(0, 2) ThisWorkbook.Activate Sheets(nlib).Select Range("A2").Select Cells.Find(what:=modelo, After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False).Activate ActiveCell.Offset(0, 3).Value = ActiveCell.Offset(0, 3).Value + cantidad Workbooks(LIBRO).Activate Sheets("Hoja1").Select ActiveCell.Offset(1, 0).Select Loop ThisWorkbook.Activate Sheets(nlib).Select

End Sub

Sub generar_pedido()Application.ScreenUpdating = False

marca = UserForm5.ComboBox1

Page 11: Factutacion Codigo Completo

Macros_Almacen - 3 Sheets("Hoja1").Activate Range("L1:M15").Find(what:=marca, LookAt:=xlWhole).Activate npedido = Application.WorksheetFunction.Text(ActiveCell.Offset(2, 0) + 1, "0000")

ActiveCell.Offset(2, 0).Value = ActiveCell.Offset(2, 0).Value + 1 ActiveCell.Offset(2, 1).Formula = "=TEXT(TODAY(),""dd-mmm-aa"")" ActiveCell.Offset(2, 1).Copy ActiveCell.Offset(2, 1).PasteSpecial xlPasteValues nombre_pedido = "PEDIDO " & marca & "-" & npedido & ".xlsx"plantilla = ThisWorkbook.Path & "\Mis Plantillas Excel\"ruta = ThisWorkbook.Path & "\Pedidos a Proveedor\"

Workbooks.Add Template:=plantilla & "PEDIDO.xltx"ActiveWorkbook.SaveAs Filename:=ruta & nombre_pedido, _ FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

ThisWorkbook.Activate Sheets(marca).Activate Range("D1").Copy Range("M1") Range("M2") = "<=5" Columns("A:D").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _ "M1:M2"), CopyToRange:=Range("O1"), Unique:=False If Range("O2") = "" Then MsgBox "TODAS LAS EXISTENCIAS ESTAN " + Chr(13) + _ "POR ENCIMA DE LAS 5 UNIDADES" Workbooks(nombre_pedido).Close Set fso = CreateObject("Scripting.FileSystemObject") fso.DeleteFile ruta & nombre_pedido, True Set fso = Nothing Sheets("Hoja1").Activate Range("L1:M15").Find(what:=marca, LookAt:=xlWhole).Activate ActiveCell.Offset(2, 0).Value = ActiveCell.Offset(2, 0).Value - 1 Sheets("INICIO").Activate Exit Sub End If Columns("Q:Q").Delete Range("Q2").SelectDo While ActiveCell <> "" ActiveCell.Value = 10 - ActiveCell.Value ActiveCell.Offset(1, 0).Select Loop Range("O2").SelectRange(Selection, Selection.End(xlToRight)).SelectIf Range("O3") <> "" Then Range(Selection, Selection.End(xlDown)).SelectEnd If

Selection.Copy

Page 12: Factutacion Codigo Completo

Macros_Almacen - 4 Workbooks(nombre_pedido).Activate Range("A2").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False ThisWorkbook.Activate Columns("M:Q").Delete Range("A1").Activate Workbooks(nombre_pedido).Activate Range("D1").Activate Application.CutCopyMode = False

End Sub

Sub lanza_facturables_alta_items() Unload UserForm1 Rellenar_facturables.CommandACEPTARP.Enabled = False Rellenar_facturables.CommandACEPTARP.Visible = False Rellenar_facturables.CommandACEPTARA.Enabled = False Rellenar_facturables.CommandACEPTARA.Visible = False Rellenar_facturables.LabePrecio.Enabled = False Rellenar_facturables.LabePrecio.Visible = False Rellenar_facturables.TextBoxCANTIDAD.Enabled = False Rellenar_facturables.TextBoxCANTIDAD.Visible = False Rellenar_facturables.TextBoxPRECIO.Enabled = False Rellenar_facturables.TextBoxPRECIO.Visible = False Rellenar_facturables.BotonCancelar.Enabled = False Rellenar_facturables.BotonCancelar.Visible = False Rellenar_facturables.Label1.Caption = "AÑADIR ELEMENTOS" Rellenar_facturables.Show

End Sub

Sub lanza_actualiza_existencias() UserForm5.CommandButton1.Enabled = False UserForm5.CommandButton1.Visible = False UserForm5.Label1.Caption = "Nombre del archivo (igual que la marca)" UserForm5.ShowEnd Sub

Sub lanza_generar_pedido() UserForm5.CommandButton2.Enabled = False UserForm5.CommandButton2.Visible = False UserForm5.Label1.Caption = "Elegir marca" UserForm5.ShowEnd Sub

Sub registro_de_pedidos()On Error Resume NextApplication.ScreenUpdating = False

Set fso = CreateObject("Scripting.FileSystemObject")ruta = ThisWorkbook.Path & "\Pedidos a Proveedor\"Set carpeta = fso.GetFolder(ruta)Set pedidos = carpeta.Files

Page 13: Factutacion Codigo Completo

Macros_Almacen - 5

Sheets("Hoja1").ActivateRange("P3").Select

For Each archivo In pedidosActiveCell = archivo.NameActiveCell.Offset(0, 1) = FormatDateTime(archivo.DateCreated, vbShortDate)ActiveCell.Offset(1, 0).SelectNext

Set fso = NothingSet carpeta = NothingSet pedidos = Nothing

Application.ScreenUpdating = TrueEnd Sub

Sub BorrarAlbarancondowhile()

Application.ScreenUpdating = FalseSheets("Albaran").SelectRange("C14").Activate

If Range("C14") = "" Then GoTo borranombreEnd If

Do While ActiveCell <> "" hoja = ActiveCell.Offset(0, -1) modelo = ActiveCell cantidad = ActiveCell.Offset(0, 2) Sheets(hoja).Select Range("A1").Select Cells.Find(what:=modelo, After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False).Activate ActiveCell.Offset(0, 3).Value = ActiveCell.Offset(0, 3).Value + cantidad Sheets("Albaran").Select ActiveCell.Offset(1, 0).Select Loop Range("B14:F52").ClearContents borranombre: Range("G5:G11").ClearContents Range("A1").ActivateEnd Sub

Page 14: Factutacion Codigo Completo

Macros_antiguas - 1 Sub facturatodos() UserForm2.Hide Range("A2").Select Range(Selection, Selection.End(xlDown)).Select Range(Selection, Selection.End(xlToRight)).Select Selection.Cut Sheets("Facturas Emitidas").Activate Range("A2").Select Selection.Insert Shift:=xlDown Sheets("Facturacion").Activate Range("A2").Select End Sub

Sub DatosCuadro4()'PASA DATOS DE FACTURA Y CLIENTE A HOJA 1 PARA EL CUADRO 4 Application.ScreenUpdating = False Sheets("Facturas Emitidas").Range("J2").Activate Range(Selection, Selection.End(xlDown)).Select Range(Selection, Selection.End(xlToRight)).Select Selection.Copy Sheets("Hoja1").Activate Range("A2").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Sheets("Facturas Emitidas").Activate Range("D2").Select Range(Selection, Selection.End(xlDown)).Select Application.CutCopyMode = False Selection.Copy Sheets("Hoja1").Activate Range("C2").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Range("A2").ActivateEnd Sub

Sub FiltraCuadro4()'FILTRA FACTURAS UNICAS PARA CUADRO 4 Application.CutCopyMode = False Columns("A:C").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _ "E1:E2"), CopyToRange:=Range("G1:I1"), Unique:=True Application.CutCopyMode = False Sheets("Facturas Emitidas").Activate End Sub

Sub Botón2_Haga_clic_en()UserForm6.ShowEnd Sub

Sub numerocliente() Sheets("Facturas emitidas").Activate Range("K2").Copy Selection.CurrentRegion.Select Selection.SpecialCells(xlCellTypeBlanks).Select

Page 15: Factutacion Codigo Completo

Macros_antiguas - 2 ActiveSheet.Paste Application.CutCopyMode = False Range("A2").SelectEnd Sub

Sub FACTURALCLIENTE()UserForm3.ShowUserForm2.ShowEnd Sub

Sub Copianumfactura()

'RELLENA CON FORMULAS DE NUMERO DE FACTURA Sheets("Facturas emitidas").Activate Range("K2").Copy Selection.CurrentRegion.Select Selection.SpecialCells(xlCellTypeBlanks).Select ActiveSheet.Paste Application.CutCopyMode = False Range("A2").SelectEnd Sub

Page 16: Factutacion Codigo Completo

Macros_nuevas - 1

Sub FACTURAYA() 'MUEVE DATOS A FACTURAS EMITIDAS

Application.ScreenUpdating = False UserForm2.Hide 'Filtramos por cliente Columns("A:J").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range _ ("M1:N2"), Unique:=False 'Localizamos el cliente para hacer la selección Cells.Find(what:=Range("M2"), After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False).Activate ' Escondemos los encabezados para seleccionar la región con los datos Rows("1:1").Hidden = True Selection.CurrentRegion.Select Selection.Copy 'vamos a la otra hoja Sheets("Facturas Emitidas").Activate Range("A1").Activate ' buscamos la 1ª fila vacía Do While Not IsEmpty(ActiveCell) ActiveCell.Offset(1, 0).Select Loop ' copiamos los datos y nº de factura ActiveSheet.Paste Application.CutCopyMode = False ' vuelta a Facturacion y borrado de datos copiados Sheets("Facturacion").Activate Selection.Delete Shift:=xlUp 'mostramos los encabezados y quitamos el filtro Range("A1").Activate Selection.EntireRow.Hidden = False ActiveSheet.ShowAllData Application.CutCopyMode = False Range("A1").Select End Sub

Sub MuestraUser7()UserForm7.ShowSheets("Presupuesto").ActivateEnd Sub

Sub MuestraUser8()UserForm8.Show

Page 17: Factutacion Codigo Completo

Macros_nuevas - 2 Sheets("Presupuesto (2)").ActivateEnd Sub

Sub RELLENENOMBREALBARAN()

Application.ScreenUpdating = False Set fila = Cells(1, 1) Sheets("Lista de Clientes").Select Cells(fila + 1, 2).Select Set varNOMBRE = ActiveCell Set varNIF = ActiveCell.Offset(0, -1) Set varDIRECCION = ActiveCell.Offset(0, 1) Set varCP = ActiveCell.Offset(0, 3) Set varTELEF = ActiveCell.Offset(0, 2) Set varEMAIL = ActiveCell.Offset(0, 4) Set varNUMCLI = ActiveCell.Offset(0, 5) Sheets("Albaran").Select Range("G7") = varNOMBRE Range("G6") = varNIF Range("G9") = varDIRECCION Range("G10") = CDbl(varCP) Range("G11") = CDbl(varTELEF) Range("G8") = varEMAIL Range("G5") = varNUMCLI End SubSub Generalbaran() 'Pasa el albarán a Facturación Application.ScreenUpdating = False

If Range("G7") = 0 Then MsgBox ("INTRODUCIR UN CLIENTE") End ElseIf Range("B14") = 0 Or Range("E14") = 0 Then MsgBox ("LA REFERENCIA O LA CANTIDAD NO PUEDE SER NULA") End ElseIf MsgBox("¿DESEA IMPRIMIR EL ALBARAN?", vbQuestion + vbYesNo) = vbYes Then IMPRIMIR End If Range("A1").Value = Range("A1").Value + 1 If Range("A1").Value > 9999 Then Range("A1").Value = 1 End If 'definimos variables para los campos Set varFECHA = Range("G2") Set varNUMALB = Range("G3") Set varNOMBRE = Range("G7") Set varNIF = Range("G6") Set varID = Range("F4")

Page 18: Factutacion Codigo Completo

Macros_nuevas - 3 Set items = Range("C54") ' copiamos los artículos del albarán Range("C14").Select If Range("C15") <> "" Then Range(Selection, Selection.End(xlDown)).Select Range(Selection, Selection.End(xlToRight)).Select Else Range(Selection, Selection.End(xlToRight)).Select End If Selection.Copy ' los llevamos a Facturación Sheets("Facturacion").Select ' buscamos la 1ª celda vacía del artículo Cells(1, 5).Select Do While Not IsEmpty(ActiveCell) ActiveCell.Offset(1, 0).Select Loop' pegamos los datos ActiveCell.PasteSpecial xlPasteValuesAndNumberFormats Application.CutCopyMode = False Cells(1, 1).Select' buscamos la 1ª celda vacía de los datos del cliente' y volcamos las variables con sus datos, tantas veces como filas hay en el albarán For I = 1 To items Do While Not IsEmpty(ActiveCell) ActiveCell.Offset(1, 0).Select Loop ActiveCell = varNUMALB ActiveCell.Offset(0, 1) = CDate(varFECHA) ActiveCell.Offset(0, 2) = varNIF ActiveCell.Offset(0, 3) = varNOMBRE ActiveCell.Offset(0, 9) = CStr(varID) Next I ' volvemos a la hoja albarán y borramos todo Sheets("Albaran").Select Range("G5:G11").ClearContents Range("B14:F52").ClearContents Range("A1").Select End Sub

Sub Generafactinmediata()

If Range("G7") = 0 Then MsgBox ("INTRODUCIR UN CLIENTE") End ElseIf Range("B14") = 0 Or Range("E14") = 0 Then MsgBox ("LA REFERENCIA O LA CANTIDAD NO PUEDE SER NULA") End

Page 19: Factutacion Codigo Completo

Macros_nuevas - 4 ElseIf MsgBox("¿DESEA IMPRIMIR LA FACTURA?", vbQuestion + vbYesNo) = vbYes Then IMPRIMIR End If Range("A1").Value = Range("A1").Value + 1

'definimos variables para los campos Set varFECHA = Range("G2") Set varNUMFACT = Range("G3") Set varNOMBRE = Range("G7") Set varNIF = Range("G6") Set varID = Range("F4") Set items = Range("C54") ' copiamos los artículos del albarán Range("C14").Select If Range("C15") <> "" Then Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).Select Else Range(Selection, Selection.End(xlToRight)).Select End If Selection.Copy ' los llevamos a Facturas Emitidas Sheets("Facturas Emitidas").Select ' buscamos la 1ª celda vacía del artículo Cells(1, 5).Select Do While Not IsEmpty(ActiveCell) ActiveCell.Offset(1, 0).Select Loop' pegamos los datos ActiveCell.PasteSpecial xlPasteValuesAndNumberFormats Application.CutCopyMode = False ' buscamos la 1ª celda vacía de los datos del cliente' y volcamos las variables con sus datos, tantas veces como filas hay en el albarán Cells(1, 1).Select For I = 1 To items Do While Not IsEmpty(ActiveCell) ActiveCell.Offset(1, 0).Select Loop ActiveCell = varNUMFACT ActiveCell.Offset(0, 1) = CDate(varFECHA) ActiveCell.Offset(0, 2) = varNIF ActiveCell.Offset(0, 3) = varNOMBRE ActiveCell.Offset(0, 9) = CStr(varID) Next I ' volvemos a la hoja albarán y borramos todo Sheets("Albaran").Select Range("G5:G11").ClearContents

Page 20: Factutacion Codigo Completo

Macros_nuevas - 5 Range("B14:F52").ClearContents Range("A1").Select

End Sub

Sub IMPRIMIR() 'IMPRIME DOCUMENTO EN IMPRESORA PREDEFINIDA ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _ IgnorePrintAreas:=FalseEnd Sub

Sub lanza_facturables_albaran() Rellenar_facturables.CommandACEPTARP.Enabled = False Rellenar_facturables.CommandACEPTARP.Visible = False Rellenar_facturables.BotonANADIRLEMENTO.Enabled = False Rellenar_facturables.BotonANADIRLEMENTO.Visible = False Rellenar_facturables.TextBoxCantAnadir.Enabled = False Rellenar_facturables.TextBoxCantAnadir.Visible = False Rellenar_facturables.LabelANADIR.Enabled = False Rellenar_facturables.LabelANADIR.Visible = False Rellenar_facturables.CommandButtonC.Enabled = False Rellenar_facturables.CommandButtonC.Visible = False Rellenar_facturables.Label1.Caption = "ELEGIR UN EQUIPO" Rellenar_facturables.ShowEnd Sub

Sub lanza_facturables_presupuesto() Rellenar_facturables.CommandACEPTARA.Enabled = False Rellenar_facturables.CommandACEPTARA.Visible = False Rellenar_facturables.BotonANADIRLEMENTO.Enabled = False Rellenar_facturables.BotonANADIRLEMENTO.Visible = False Rellenar_facturables.TextBoxCantAnadir.Enabled = False Rellenar_facturables.TextBoxCantAnadir.Visible = False Rellenar_facturables.LabelANADIR.Enabled = False Rellenar_facturables.LabelANADIR.Visible = False Rellenar_facturables.CommandButtonC.Enabled = False Rellenar_facturables.CommandButtonC.Visible = False Rellenar_facturables.Label1.Caption = "ELEGIR UN EQUIPO" Rellenar_facturables.ShowEnd SubSub Imprimefacturas() Application.ScreenUpdating = FalseOn Error Resume NextSheets("Hoja1").Range("A2:C1000").ClearContentsSheets("Hoja3").Range("B10:H1000").ClearContents

DatosCuadro4 FiltraCuadro4 UserForm4.Show Range("A2").Select Columns("A:K").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _ "M1:N2"), CopyToRange:=Range("Q1:AA1"), Unique:=False Application.CutCopyMode = False Range("Q2:R2").Select If Range("Q3") <> "" Then

Page 21: Factutacion Codigo Completo

Macros_nuevas - 6 Range(Selection, Selection.End(xlDown)).Select End If Selection.Copy

Sheets("Hoja3").Select Range("B10").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Sheets("Facturas Emitidas").Select Range("U2:Y2").Select If Range("Q3") <> "" Then Range(Selection, Selection.End(xlDown)).Select End If Selection.Copy

Sheets("Hoja3").Select Range("D10").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Range("H10").Select Do While Not IsEmpty(ActiveCell) ActiveCell.Offset(1, 0).Select Loop ActiveCell.Offset(1, 0).Select ActiveCell.FormulaR1C1 = "=sum(R10C:R[-2]C)" ActiveCell.Offset(1, 0).FormulaR1C1 = "=(R[-1]C)*18%" ActiveCell.Offset(2, 0).FormulaR1C1 = "=sum(R[-1]C:R[-2]C)" ActiveCell.Offset(0, -1).Value = "Suma" ActiveCell.Offset(1, -1).Value = "IVA 18%" ActiveCell.Offset(2, -1).Value = "Total" AreaImpresionEnd Sub

Sub AreaImpresion()

Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Activate With ActiveCell.Offset(2, 0) celda = .Address End With ActiveSheet.PageSetup.PrintArea = "$B$1:" & celdaEnd Sub

Page 22: Factutacion Codigo Completo

Rellenar_facturables - 1 Private Sub BotonANADIRLEMENTO_Click()Application.ScreenUpdating = FalseIf ComboMARCA = "" Or ComboMODELO = "" Or TextBoxCantAnadir = "" Then MsgBox "RELLENE TODOS LOS CAMPOS POR FAVOR", vbExclamation ComboMARCA.Clear ComboMODELO.Clear Unload Rellenar_facturables Exit Sub End If On Error Resume Next ActiveCell.Offset(0, 2).Value = ActiveCell.Offset(0, 2).Value + TextBoxCantAnadir

ComboMARCA.Clear ComboMODELO.Clear TextBoxMODELO = "" TextBoxCantAnadir = "" With TextBoxSTOCK .Value = "" .BackColor = vbWhite .ForeColor = vbBlack .Font.Bold = False End With Application.ScreenUpdating = True End Sub

Private Sub CommandButtonCANCELAR_Click() 'Cancela y borra formularioOn Error Resume Next ComboMARCA.Clear ComboMODELO.Clear TextBoxMODELO = "" TextBoxCANTIDAD = "" TextBoxPRECIO = "" TextBoxSTOCK = "" TextBoxCantAnadir = "" Unload Rellenar_facturables Range("A1").SelectEnd Sub

Private Sub BotonCancelar_Click()

ComboMARCA.Clear ComboMODELO.Clear TextBoxMODELO = "" TextBoxCANTIDAD = "" TextBoxPRECIO = "" Unload Rellenar_facturablesEnd Sub

Private Sub ComboMARCA_Enter() 'Carga marcas en combo

Page 23: Factutacion Codigo Completo

Rellenar_facturables - 2 On Error Resume Next ComboMODELO.Clear For l = 10 To Sheets.Count ComboMARCA.AddItem Sheets(l).Name Next End Sub

Private Sub ComboMODELO_Change() 'Carga datos en los textbox On Error Resume Next

Cells(ComboMODELO.ListIndex + 2, 2).Select TextBoxMODELO = ActiveCell.Offset(0, -1) TextBoxPRECIO = ActiveCell.Offset(0, 1) & " €" TextBoxSTOCK = ActiveCell.Offset(0, 2) End Sub

Private Sub ComboMODELO_Enter() 'Carga los descripciones en el combo On Error Resume Next Application.ScreenUpdating = False

ComboMODELO.Clear lista_corresp = ComboMARCA.List(ComboMARCA.ListIndex) Sheets(lista_corresp).Select

Range("B2").Select Do While Not IsEmpty(ActiveCell) ComboMODELO.AddItem ActiveCell ActiveCell.Offset(1, 0).Select Loop End Sub

Private Sub CommandACEPTARP_Click() ''Vuelca datos a la hoja Presupuesto (2)

Sheets("Presupuesto (2)").Select If ComboMARCA = "" Or ComboMODELO = "" Or TextBoxCANTIDAD = "" Then MsgBox ("RELLENE TODOS LOS CAMPOS POR FAVOR") ComboMARCA.Clear ComboMODELO.Clear Unload Rellenar_facturables End If

On Error Resume Next ActiveCell = ComboMARCA ActiveCell.Offset(0, 1) = TextBoxMODELO ActiveCell.Offset(0, 2) = ComboMODELO ActiveCell.Offset(0, 3) = TextBoxCANTIDAD ActiveCell.Offset(0, 4) = CDbl(TextBoxPRECIO)

Page 24: Factutacion Codigo Completo

Rellenar_facturables - 3 ComboMARCA.Clear ComboMODELO.Clear TextBoxMODELO = "" TextBoxCANTIDAD = "" TextBoxPRECIO = "" Unload Rellenar_facturables Rellenar_facturables.Hide Range("A1").Select End Sub

Private Sub CommandACEPTARA_Click() 'Vuelca datos a la hoja albarán If ComboMARCA = "" Or ComboMODELO = "" Or TextBoxCANTIDAD = "" Then MsgBox "RELLENE TODOS LOS CAMPOS POR FAVOR", vbExclamation ComboMARCA.Clear ComboMODELO.Clear Unload Rellenar_facturables Exit Sub End If ActiveCell.Offset(0, 2).Value = ActiveCell.Offset(0, 2) - TextBoxCANTIDAD Sheets("Albaran").Select On Error Resume Next ActiveCell = ComboMARCA ActiveCell.Offset(0, 1) = TextBoxMODELO ActiveCell.Offset(0, 2) = ComboMODELO ActiveCell.Offset(0, 3) = TextBoxCANTIDAD ActiveCell.Offset(0, 4) = CDbl(TextBoxPRECIO) ComboMARCA.Clear ComboMODELO.Clear TextBoxCANTIDAD = "" TextBoxMODELO = "" TextBoxPRECIO = "" Unload Rellenar_facturables End Sub

Private Sub CommandButtonC_Click()

ComboMARCA.Clear ComboMODELO.Clear TextBoxMODELO = "" TextBoxSTOCK = "" TextBoxCantAnadir = "" Unload Rellenar_facturables Sheets("INICIO").ActivateEnd Sub

Page 25: Factutacion Codigo Completo

Rellenar_facturables - 4 Private Sub TextBoxSTOCK_Change()With TextBoxSTOCK If .Value < 3 Then .BackColor = vbRed .ForeColor = vbWhite .Font.Bold = True MsgBox "LAS EXISTENCIAS ESTÁN BAJ0 MINIMOS", vbCritical Exit Sub End If If .Value < 5 Then .BackColor = &HFFFF& .ForeColor = vbRed .Font.Bold = True MsgBox "QUEDAN MENOS DE CINCO ITEMS EN EL ALMACEN", vbExclamation End IfEnd WithEnd Sub

Private Sub UserForm_Deactivate() 'Rehabilita los botones CommandButtonACEPTARA.Enabled = True CommandButtonACEPTARA.Visible = True CommandACEPTARP.Enabled = True CommandACEPTARP.Visible = True End Sub

Page 26: Factutacion Codigo Completo

ThisWorkbook - 1 Private Sub Workbook_Open()Sheets("INICIO").ScrollArea = "A1:T50"Sheets("INICIO").ActivateEnd Sub

Page 27: Factutacion Codigo Completo

UserForm1 - 1 Private Sub CommandButton1_Click() lanza_facturables_alta_items Unload UserForm1End Sub

Private Sub CommandButton1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)CommandButton1.ForeColor = &HFFFF&End Sub

Private Sub CommandButton2_Click()CuadroMsgItems.Showlanza_actualiza_existenciasUnload UserForm1End Sub

Private Sub CommandButton2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)CommandButton2.ForeColor = &HFFFF&End Sub

Private Sub CommandButton3_Click()lanza_generar_pedidoUnload UserForm1End Sub

Private Sub CommandButton3_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)CommandButton3.ForeColor = &HFFFF&End Sub

Private Sub CommandButton4_Click()registro_de_pedidosUnload UserForm1End Sub

Private Sub CommandButton4_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)CommandButton4.ForeColor = &HFFFF&End Sub

Private Sub CommandButton5_Click()Unload UserForm1

End Sub

Private Sub CommandButton5_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)CommandButton5.ForeColor = &HFFFF&End Sub

Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)CommandButton1.ForeColor = vbBlackCommandButton2.ForeColor = vbBlack

Page 28: Factutacion Codigo Completo

UserForm1 - 2 CommandButton3.ForeColor = vbBlackCommandButton4.ForeColor = vbBlackCommandButton5.ForeColor = vbBlackEnd Sub

Page 29: Factutacion Codigo Completo

UserForm2 - 1 Private Sub CommandButton1_Click() FACTURAYAEnd Sub

Private Sub Label2_Click()facturatodosEnd Sub

Page 30: Factutacion Codigo Completo

UserForm3 - 1

Private Sub CommandButton1_Click()ActiveSheet.Range("A2").SelectUserForm3.Hide

End Sub

Private Sub CommandButton2_Click()ActiveSheet.Range("A2").SelectUserForm3.HideEndEnd Sub

Page 31: Factutacion Codigo Completo

UserForm4 - 1

Private Sub ComboBox1_Change()

End Sub

Private Sub CommandButton1_Click()

UserForm4.Hide

End Sub

Private Sub Label1_Click()

End Sub

Private Sub UserForm_Click()

End Sub

Page 32: Factutacion Codigo Completo

UserForm5 - 1 Private Sub ComboBox1_Enter() On Error Resume Next For l = 10 To Sheets.Count ComboBox1.AddItem Sheets(l).Name Next End Sub

Private Sub CommandButton1_Click()generar_pedidoUnload UserForm5End Sub

Private Sub CommandButton2_Click()actualiza_existenciasUnload UserForm5End Sub

Page 33: Factutacion Codigo Completo

UserForm7 - 1

Private Sub ACEPTAR_Click()

Application.ScreenUpdating = False

Sheets("Presupuesto (2)").Activate Range("G6") = TextBoxNIF Range("G7") = ComboBoxNOMBRE Range("G8") = TextBoxDIRECCION Range("G9") = CDbl(TextBoxCP) Range("G10") = CDbl(TextBoxTELEF) Range("D7") = TextBoxEMAIL Range("D8") = TextBoxNUMCLI ComboBoxNOMBREF = "" TextBoxNIF = "" TextBoxDIRECCION = "" TextBoxCP = "" TextBoxTELEF = "" TextBoxEMAIL = "" TextBoxNUMCLI = "" UserForm7.Hide End Sub

Private Sub CANCELAR_Click() ComboBoxNOMBRE = "" TextBoxNIF = "" TextBoxDIRECCION = "" TextBoxCP = "" TextBoxTELEF = "" TextBoxEMAIL = "" TextBoxNUMCLI = "" Do While Not IsEmpty(ActiveCell) ActiveCell.Offset(1, 0).Activate Loop ComboBoxNOMBRE.SetFocus End Sub

Private Sub ComboBoxNOMBRE_Change()

Application.ScreenUpdating = False Cells(ComboBoxNOMBRE.ListIndex + 2, 2).Select TextBoxNIF = ActiveCell.Offset(0, -1) TextBoxDIRECCION = ActiveCell.Offset(0, 1) TextBoxCP = ActiveCell.Offset(0, 3) TextBoxTELEF = ActiveCell.Offset(0, 2) TextBoxEMAIL = ActiveCell.Offset(0, 4) TextBoxNUMCLI = ActiveCell.Offset(0, 5)

Page 34: Factutacion Codigo Completo

UserForm7 - 2 End Sub

Private Sub ComboBoxNOMBRE_Enter()

Application.ScreenUpdating = False

ComboBoxNOMBRE.Clear Sheets("Lista de Clientes").Select Range("B2").Select

Do While Not IsEmpty(ActiveCell) ComboBoxNOMBRE.AddItem ActiveCell.Value ActiveCell.Offset(1, 0).Select Loop

End Sub

Private Sub UserForm_Activate()

TextBoxNIF = "" ComboBoxNOMBRE.Clear TextBoxDIRECCION = "" TextBoxCP = "" TextBoxTELEF = "" TextBoxEMAIL = "" ComboBoxNUMCLI = "" ComboBoxNOMBRE.SetFocus

End Sub

Page 35: Factutacion Codigo Completo

UserForm8 - 1

Private Sub BotonBAJA_Click()If MsgBox("¿SEGURO QUE QUIERE ELIMINAR ESTE CLIENTE?", vbExclamation + vbYesNo) = vbYes Then ActiveCell.EntireRow.Delete Shift = xlUp ComboBoxNIF2 = "" TextBoxNOMBRE = "" TextBoxDIRECCION = "" TextBoxCP = "" TextBoxTELEF = "" TextBoxEMAIL = ""

If MsgBox("EL CLIENTE HA SIDO ELIMINADO. ¿Quiere cerrar el formulario?", vbInformation + vbYesNo) = vbYes Then UserForm8.Hide End IfEnd IfEnd Sub

Private Sub BotonCancelar_Click() ComboBoxNIF2 = "" TextBoxNOMBRE = "" TextBoxDIRECCION = "" TextBoxCP = "" TextBoxTELEF = "" TextBoxEMAIL = "" Do While Not IsEmpty(ActiveCell) ActiveCell.Offset(1, 0).Activate Loop ComboBoxNIF.SetFocusEnd Sub

Private Sub BotonBAJA_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)BotonBAJA.BackStyle = fmBackStyleOpaqueBotonBAJA.ForeColor = vbWhiteEnd Sub

Private Sub ButtonCANCELAR_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)ButtonCANCELAR.BackStyle = fmBackStyleOpaqueButtonCANCELAR.ForeColor = vbWhiteEnd Sub

Private Sub ButtonModif_Click() Application.ScreenUpdating = False Sheets("Lista de Clientes").Activate Cells(ComboBoxNIF2.ListIndex + 2, 1).Select ActiveCell.Offset(0, 1) = TextBoxNOMBRE ActiveCell.Offset(0, 2) = TextBoxDIRECCION ActiveCell.Offset(0, 4) = CDbl(TextBoxCP)

Page 36: Factutacion Codigo Completo

UserForm8 - 2 ActiveCell.Offset(0, 3) = CDbl(TextBoxTELEF) ActiveCell.Offset(0, 5) = TextBoxEMAIL TextBoxNIF = "" TextBoxNOMBRE = "" TextBoxDIRECCION = "" TextBoxCP = "" TextBoxTELEF = "" TextBoxEMAIL = ""

UserForm8.Hide

End Sub

Private Sub ButtonModif_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) ButtonModif.ForeColor = vbBlack ButtonModif.BackStyle = fmBackStyleOpaqueEnd Sub

Private Sub ComboBoxNIF2_Change() Application.ScreenUpdating = False Sheets("Lista de Clientes").Activate

On Error Resume Next Cells(ComboBoxNIF2.ListIndex + 2, 1).Select TextBoxNOMBRE = ActiveCell.Offset(0, 1) TextBoxDIRECCION = ActiveCell.Offset(0, 2) TextBoxCP = ActiveCell.Offset(0, 4) TextBoxTELEF = ActiveCell.Offset(0, 3) TextBoxEMAIL = ActiveCell.Offset(0, 5)

End Sub

Private Sub ComboBoxNIF2_Enter() Application.ScreenUpdating = False

ComboBoxNIF2.Clear Sheets("Lista de Clientes").Select Range("a2").Select

Do While Not IsEmpty(ActiveCell) ComboBoxNIF2.AddItem ActiveCell.Value ActiveCell.Offset(1, 0).Select Loop

End Sub

Private Sub LabelAlta_Click() ComboBoxNIF2.Enabled = False ComboBoxNIF2.Visible = False

Page 37: Factutacion Codigo Completo

UserForm8 - 3 TextBoxNIF.Enabled = True TextBoxNIF.Visible = True BotonBAJA.Enabled = False BotonBAJA.Visible = False ButtonModif.Enabled = False ButtonModif.Visible = False Validar.Enabled = True Validar.Visible = True ButtonCANCELAR.Enabled = True ButtonCANCELAR.Visible = TrueEnd Sub

Private Sub LabelAlta_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) LabelAlta.ForeColor = &HFFFF00 End Sub

Private Sub LabelMod_Click() TextBoxNIF.Enabled = False TextBoxNIF.Visible = False ComboBoxNIF2.Enabled = True ComboBoxNIF2.Visible = True ComboBoxNIF2 = "" Validar.Enabled = False Validar.Visible = False ButtonModif.Enabled = True ButtonModif.Visible = True BotonBAJA.Enabled = True BotonBAJA.Visible = True ButtonCANCELAR.Enabled = True ButtonCANCELAR.Visible = TrueEnd Sub

Private Sub LabelMod_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) LabelMod.ForeColor = &H80FFFF End Sub

Private Sub UserForm_Activate() ComboBoxNIF2 = "" TextBoxNIF = "" TextBoxNOMBRE = "" TextBoxDIRECCION = "" TextBoxCP = "" TextBoxTELEF = "" TextBoxEMAIL = "" Do While Not IsEmpty(ActiveCell) ActiveCell.Offset(1, 0).Activate Loop BotonBAJA.Enabled = False BotonBAJA.Visible = False ButtonModif.Enabled = False ButtonModif.Visible = False

Page 38: Factutacion Codigo Completo

UserForm8 - 4 Validar.Enabled = False Validar.Visible = False ButtonCANCELAR.Enabled = False ButtonCANCELAR.Visible = False End Sub

Private Sub ButtonCANCELAR_Click() ComboBoxNIF2 = "" TextBoxNIF = "" TextBoxNOMBRE = "" TextBoxDIRECCION = "" TextBoxCP = "" TextBoxTELEF = "" TextBoxEMAIL = "" Do While Not IsEmpty(ActiveCell) ActiveCell.Offset(1, 0).Activate LoopEnd Sub

Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)LabelAlta.ForeColor = vbWhiteLabelMod.ForeColor = &H80FF80BotonBAJA.BackStyle = fmBackStyleTransparentBotonBAJA.ForeColor = &HFF&ButtonCANCELAR.BackStyle = fmBackStyleTransparentButtonCANCELAR.ForeColor = &H80FF80ButtonModif.ForeColor = &HFFFF&ButtonModif.BackStyle = fmBackStyleTransparentValidar.BackStyle = fmBackStyleTransparentValidar.ForeColor = &HFFFF&End Sub

Private Sub Validar_Click() Application.ScreenUpdating = False Sheets("Lista de Clientes").Activate Range("a2").Activate Do While Not IsEmpty(ActiveCell) ActiveCell.Offset(1, 0).Activate Loop ActiveCell = TextBoxNIF ActiveCell.Offset(0, 1) = TextBoxNOMBRE ActiveCell.Offset(0, 2) = TextBoxDIRECCION ActiveCell.Offset(0, 4) = CDbl(TextBoxCP) ActiveCell.Offset(0, 3) = CDbl(TextBoxTELEF) ActiveCell.Offset(0, 5) = TextBoxEMAIL Range("G2").Copy ActiveCell.Offset(0, 6).PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Application.CutCopyMode = False

Page 39: Factutacion Codigo Completo

UserForm8 - 5 TextBoxNIF = "" TextBoxNOMBRE = "" TextBoxDIRECCION = "" TextBoxCP = "" TextBoxTELEF = "" TextBoxEMAIL = ""

UserForm8.Hide

End Sub

Private Sub Validar_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) Validar.BackStyle = fmBackStyleOpaque Validar.ForeColor = &H0&End Sub

Page 40: Factutacion Codigo Completo

UserForm9 - 1

Private Sub ComboBox1_Enter() Application.ScreenUpdating = False

ComboBox1.Clear Sheets("Lista de Clientes").Select Range("B2").Select

Do While Not IsEmpty(ActiveCell) ComboBox1.AddItem ActiveCell.Value ActiveCell.Offset(1, 0).Select Loop End Sub

Private Sub CommandButton1_Click() Application.ScreenUpdating = False On Error Resume Next Cells(ComboBox1.ListIndex + 2, 2).Select Set varNOMBRE = ActiveCell Set varNIF = ActiveCell.Offset(0, -1) Set varDIRECCION = ActiveCell.Offset(0, 1) Set varCP = ActiveCell.Offset(0, 3) Set varTELEF = ActiveCell.Offset(0, 2) Set varEMAIL = ActiveCell.Offset(0, 4) Set varNUMCLI = ActiveCell.Offset(0, 5) Sheets("Albaran").Select Range("G7") = varNOMBRE Range("G6") = varNIF Range("G9") = varDIRECCION Range("G10") = CDbl(varCP) Range("G11") = CDbl(varTELEF) Range("G8") = varEMAIL Range("G5") = varNUMCLI Unload UserForm9 UserForm9.Hide Range("B14").Select End Sub

Private Sub Label1_Click()

End Sub

Private Sub UserForm_Activate()

End Sub