Using multiple input boxes

Mac1512

Board Regular
Joined
Jul 26, 2011
Messages
58
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
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top