That works on the input sheet........ Thanks - If the inputter deletes the cell how can i amend the code to delete th entry in column I........ I think just add another case line with " "???
But what i would like to do is insert the code into a a code I have written to extract data from the input sheet - so when the data gets to the new sheet its there.........
So the question is how to compine two seperate codes.......
Public Sub Demo()
Dim ResultRowCount As Long
' config here
Const AccountColumn As Integer = 1
Const DateColumn As Integer = 2
Const DirectoryToSaveIn As String = "C:\test\"
tryAgain:
StartDate = Application.InputBox("Start Date i.e. 01/01/2011", "StartDate ")
If StartDate = False Then Exit Sub
'Validation of date format
If Not StartDate Like "##/##/####" Then
msg = "Entry must be dd/mm/yyyy format"
pt = MsgBox(msg, vbExclamation, "Invalid entry")
GoTo tryAgain
End If
If Not IsDate(StartDate) Then
msg = "Entry must be dd/mm/yyyy format"
pt = MsgBox(msg, vbExclamation, "Invalid entry")
GoTo tryAgain
End If
tryAgain1:
EndDate = Application.InputBox("End Date i.e. 31/01/2011", "End Date")
If EndDate = False Then Exit Sub
'Validation of date format
If Not EndDate Like "##/##/####" Then
msg = "Entry must be dd/mm/yyyy format"
pt = MsgBox(msg, vbExclamation, "Invalid entry")
GoTo tryAgain1
End If
If Not IsDate(EndDate) Then
msg = "Entry must be dd/mm/yyyy format"
pt = MsgBox(msg, vbExclamation, "Invalid entry")
GoTo tryAgain1
End If
AccountNumber = Application.InputBox("Account Number", "Account Number")
If AccountNumber = False Then Exit Sub
' Copy sheet
ActiveSheet.Copy
' Set up Criteria for advanced filter
Range("X1").Value = Cells(1, AccountColumn).Value
Range("Y1").Value = Cells(1, DateColumn).Value
Range("Z1").Value = Cells(1, DateColumn).Value
Range("X2").Value = AccountNumber
Range("Y2").Value = ">=" & Format(StartDate, "mm/dd/yyyy")
Range("Z2").Value = "<=" & Format(EndDate, "mm/dd/yyyy")
' Apply Advanced Filter
Columns("$A:$I").AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Range("$X$1:$Z$2"), CopyToRange:=Range("$AA$1"), Unique:=False
' Get Rid of old data
Columns("A:Z").Delete
ActiveWindow.FreezePanes = False
Columns("B:C").Clear
Columns("E:E").Clear
Columns("G:H").Clear
Columns("f:f").NumberFormat = "0.00"
Columns("d:d").NumberFormat = "0"
Rows("1:1").Delete Shift:=xlUp
Cells.Interior.ColorIndex = xlNone
Columns("A:A").Cut Destination:=Range("I:I")
ResultRowCount = Cells.Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
RunningTotal = 0
For Each TheNum In Columns("f:f").SpecialCells(xlCellTypeConstants, 1)
If TheNum.NumberFormat = "0.00" Then
TheNum.Offset(0, 5).Value = 40
RunningTotal = RunningTotal + TheNum.Value
End If
LastRow = TheNum.Row
Next TheNum
For Each TheNuma In Columns("f:f").SpecialCells(xlCellTypeConstants, 1)
If TheNuma.NumberFormat = "0.00" Then
TheNuma.Offset(0, 9).Value = 600000
RunningTotal = RunningTotal + TheNuma.Value
End If
LastRow = TheNuma.Row
Next TheNuma
Cells(LastRow + 1, "F").Value = RunningTotal
Cells(LastRow + 1, "K").Value = 50
Cells(LastRow + 1, "L").Value = 600000
Cells(LastRow + 1, "O").Value = 600000
Cells(LastRow + 1, "D").Value = "Revokes Vehicle"
Columns("F:F").Cut Destination:=Range("J:J")
Columns("D:D").Cut Destination:=Range("R:R")
Range("A1").Value = "DFT"
Range("B1").Value = "6000"
Range("C1").Value = "ZA"
Range("D1").Value = "GBP"
Range("E1").Value = "DVLA"
Range("F1").Value = "DVLA"
Range("G1").Value = Format(StartDate, "dd.mm.yy")
Range("H1").Value = Format(Date, "dd.mm.yy")
Range("P1").Value = "MTA_0001"
Range("A:A").EntireColumn.HorizontalAlignment = xlLeft
Range("B:B").EntireColumn.HorizontalAlignment = xlRight
Range("C:H").EntireColumn.HorizontalAlignment = xlLeft
Range("I:O").EntireColumn.HorizontalAlignment = xlRight
Range("P:R").EntireColumn.HorizontalAlignment = xlLeft
ResultRowCount = Cells.Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
' Save File New Name
Filename = AccountNumber & "_" & Format(StartDate, "mmm_yy") & ".xls"
ActiveWorkbook.SaveAs Filename:=DirectoryToSaveIn & Filename
ActiveWorkbook.Close
'Inform user of results
ln1 = "Location : " & DirectoryToSaveIn & vbNewLine
ln2 = "FileName : " & Filename & vbNewLine
ln3 = "Row Count: " & ResultRowCount & vbNewLine
msg = ln1 & ln2 & ln3
pt = MsgBox(msg, vbInformation, "Process Complete")
End Sub
Bookmarks