LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Snag in invoice generator. How to change the "series"

I have made some modifications to this code I found by McGimpsey.
Say the invoice number gets to a certain number, then I want to be able to change the 'series' say from 1000 to "A " & 0 so that the new numbers come out
A0001, A0002 etc.

The commented out if statement below is my best shot at it but it errors out on the line-- SaveSetting sAPPLICATION, sSECTION, sKEY, nNumber + 1&

Code works okay without the if statement.

I'm thinking that the final goal would be to make the "A" a variable that can be changed on the sheet to indicate what department used a particular invoice number.

If I can get past the nNumber format issue, I believe I can work out the variable issue on the myself.

Thanks.
Howard



Option Explicit

Private Sub Workbook_BeforeClose(Cancel As Boolean)
With ThisWorkbook.Sheets("Invoice")
Range("B2").ClearContents
End With
ActiveWorkbook.Save
End Sub

'McGimpsey and Associates
' Goes in ThisWorkbook module

Private Sub Workbook_Open()
Const sAPPLICATION As String = "Excel"
Const sSECTION As String = "Invoice"
Const sKEY As String = "Invoice_key"
Const nDEFAULT As Long = 1&
Dim nNumber As String 'Long
Dim lr As Long
Dim DeptNme As String

lr = Cells(Rows.Count, 11).End(xlUp).Row

'InputBox(prompt[, title] [, default] [, xpos] [, ypos] [, helpfile, context])
DeptNme = InputBox("Enter you Dept. Name.", "Department Name")
'Exit sub if Cancel button used or no text entered
If DeptNme = vbNullString Then Exit Sub

With ThisWorkbook.Sheets("Invoice")
With .Range("B1")
If IsEmpty(.Value) Then
.Value = Date
.NumberFormat = "dd mmm yyyy"
End If
End With

With .Range("K1")
If IsEmpty(.Value) Then
.Value = "Used Invoice No.'s"
.Columns.AutoFit
End If
End With

With .Range("J1")
If IsEmpty(.Value) Then
.Value = "Department"
.Columns.AutoFit
End If
End With

With .Range("B2")
If IsEmpty(.Value) Then
nNumber = GetSetting(sAPPLICATION, sSECTION, sKEY, nDEFAULT)
.NumberFormat = "@"

'//****
' If nNumber = 5 Then
' nNumber = "A" & 0
' End If
'//****

.Value = Format(nNumber, "0000")
SaveSetting sAPPLICATION, sSECTION, sKEY, nNumber + 1&

.Copy Range("K" & lr).Offset(1, 0)
Range("J" & lr).Offset(1, 0).Value = DeptNme
End If
End With
End With

End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I change the column heading in Excel to display "A" "B" "C Thai New Users to Excel 1 November 30th 07 08:06 PM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
Change default in input box from "20" to "000000"? Have macro continue on to name sheet tab? StargateFanFromWork[_4_] Excel Programming 7 October 29th 06 11:46 AM
=IF(D13="PAID","YES","NO") Can I change fonts colour Kev Excel Discussion (Misc queries) 3 February 17th 06 04:27 AM
Adding "New" "Insert" "Delete" into a workbook to change from data 1 to data 2 etc Bob Reynolds[_2_] Excel Programming 0 March 4th 04 08:52 PM


All times are GMT +1. The time now is 03:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"