Hi guys, I am new to macros and have written the below macro that creates an invoice from one company to another company based on a data sheet
The macro works fine for 1 invoice but i am trying to get it to work for multiple input boxs.
How Macro Works
Input box asks for 1st company number (Issuer) and 2nd company number (receiver) eg 1 to 2 this then creates the invoice.
I am trying to get the macro to ask for the input box to appear x number of times and create more than 1 invoice (Could be 200 invoices). I have tried using some sort of loop but unable to get it to work.
Sub Macro1()
Application.ScreenUpdating = False
Dim COnum As Integer
Dim INTnum As Integer
COnum = InputBox(Prompt:="Co Num", _
Title:="ENTER Num", Default:="Num Here")
INTnum = InputBox(Prompt:="INT Co Num", _
Title:="ENTER Num", Default:="Num Here")
'Autofilter'
Sheets("Data").Select
Rows("1:1").Select
Selection.AutoFilter
Range("A1").Select
ActiveSheet.Range("$A$1:$E$6").AutoFilter Field:=1, Criteria1:=COnum, _
Operator:=xlAnd
ActiveSheet.Range("$A$1:$E$6").AutoFilter Field:=3, Criteria1:=INTnum, _
Operator:=xlAnd
Cells.Select
Selection.Copy
'Insert sheet'
Sheets.Add.Name = "InvDetail"
Range("A1").Select
ActiveSheet.Paste
Range("A1").Select
Sheets("InvDetail").Select
Application.CutCopyMode = False
Selection.AutoFilter
Range("A1").Select
Selection.AutoFilter
Sheets("Data").Select
Selection.AutoFilter
'Link data to Invoice'
Sheets("Template").Select
Range("A6") = COnum
Range("B6") = INTnum
'Formula for sumif'
Range("I31").Select
ActiveCell.FormulaR1C1 = "=SUMIF(InvDetail!C[-3],Template!RC[-8],InvDetail!C[-4])"
Range("I31").Select
Selection.Copy
Range("I33").Select
ActiveSheet.Paste
Range("I35").Select
ActiveSheet.Paste
Range("I37").Select
ActiveSheet.Paste
Range("I39").Select
ActiveSheet.Paste
Range("I42").Select
Application.CutCopyMode = False
'Save to File'
ActiveWorkbook.SaveAs Filename:="C:\Deano\Macros\Projects\Invoice\" & Range("A6") & "_" & Range("B6"), FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
ActiveWorkbook.Close SaveChanges:=False
Application.ScreenUpdating = True
End Sub
The macro works fine for 1 invoice but i am trying to get it to work for multiple input boxs.
How Macro Works
Input box asks for 1st company number (Issuer) and 2nd company number (receiver) eg 1 to 2 this then creates the invoice.
I am trying to get the macro to ask for the input box to appear x number of times and create more than 1 invoice (Could be 200 invoices). I have tried using some sort of loop but unable to get it to work.
Sub Macro1()
Application.ScreenUpdating = False
Dim COnum As Integer
Dim INTnum As Integer
COnum = InputBox(Prompt:="Co Num", _
Title:="ENTER Num", Default:="Num Here")
INTnum = InputBox(Prompt:="INT Co Num", _
Title:="ENTER Num", Default:="Num Here")
'Autofilter'
Sheets("Data").Select
Rows("1:1").Select
Selection.AutoFilter
Range("A1").Select
ActiveSheet.Range("$A$1:$E$6").AutoFilter Field:=1, Criteria1:=COnum, _
Operator:=xlAnd
ActiveSheet.Range("$A$1:$E$6").AutoFilter Field:=3, Criteria1:=INTnum, _
Operator:=xlAnd
Cells.Select
Selection.Copy
'Insert sheet'
Sheets.Add.Name = "InvDetail"
Range("A1").Select
ActiveSheet.Paste
Range("A1").Select
Sheets("InvDetail").Select
Application.CutCopyMode = False
Selection.AutoFilter
Range("A1").Select
Selection.AutoFilter
Sheets("Data").Select
Selection.AutoFilter
'Link data to Invoice'
Sheets("Template").Select
Range("A6") = COnum
Range("B6") = INTnum
'Formula for sumif'
Range("I31").Select
ActiveCell.FormulaR1C1 = "=SUMIF(InvDetail!C[-3],Template!RC[-8],InvDetail!C[-4])"
Range("I31").Select
Selection.Copy
Range("I33").Select
ActiveSheet.Paste
Range("I35").Select
ActiveSheet.Paste
Range("I37").Select
ActiveSheet.Paste
Range("I39").Select
ActiveSheet.Paste
Range("I42").Select
Application.CutCopyMode = False
'Save to File'
ActiveWorkbook.SaveAs Filename:="C:\Deano\Macros\Projects\Invoice\" & Range("A6") & "_" & Range("B6"), FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
ActiveWorkbook.Close SaveChanges:=False
Application.ScreenUpdating = True
End Sub