Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Monty
 
Posts: n/a
Default problem with ref

I am new to all this, so i will try and explian what I am
trying to achieve with this workbook.
i want to be able to open this workbook with three
worksheets, and all worksheets will have the following
headings in A1(Batch No), B1(Date Sent), C1(Amount) & D1
(Date Paid).
In sheet 1 when you click the command button I would like
to generate a numeric number which would appear in A2,
then if I require a further number this time when I click
the command button the next number would appear in A2.

I have the following macro running which works fine for
the first part of this problem.

Public Sub RCA()
If IsEmpty(Range("A2").Value) Then
Range("A2").Value = InputBox("Enter Starting
Value")
Else
Range("A" & Rows.Count).End(xlUp).Offset(1,
0).Value = _
Application.Max(Range("A:A")) + 1
End If
End Sub

How can I adapt the above macro or use another in order
to achieve the following in sheet 2 & 3.

In sheet 2 I would like the same to happen except the
batch number in cell A2, A3, A4 etc needs to start with
the ref PCI followed by the first number for example
(PCI1, PCI2, PCI3 and so on).
I would like the same thing to happen in sheet 3 however
the ref in cell A2 A3, A4 etc need to start with the ref
PCICR followed by the first number for example (PCICR1,
PCICR2, PCICR3 and so on).

Hope you can understand this thanks for any help.


  #2   Report Post  
Jim Rech
 
Posts: n/a
Default

If you put your prefix in some out of the way cell (I'm using AA1, for the
first sheet this cell would be empty) then you could use the same routine of
all worksheets:

Sub EnterNextNumber()
Dim LastCell As Range
Dim NextNum As Long
Dim Prefix As String
Prefix = Range("AA1").Value
Set LastCell = Range("A65536").End(xlUp)
If LastCell.Row = 1 Then
On Error Resume Next
NextNum = InputBox("Enter Starting Value")
If NextNum = 0 Then
Exit Sub ''No entry, cancel or non-numeric...
End If
Else
NextNum = Mid(LastCell.Value, Len(Prefix) + 1) + 1
End If
LastCell.Offset(1).Value = Prefix & NextNum
End Sub


--
Jim Rech
Excel MVP
"Monty" wrote in message
...
|I am new to all this, so i will try and explian what I am
| trying to achieve with this workbook.
| i want to be able to open this workbook with three
| worksheets, and all worksheets will have the following
| headings in A1(Batch No), B1(Date Sent), C1(Amount) & D1
| (Date Paid).
| In sheet 1 when you click the command button I would like
| to generate a numeric number which would appear in A2,
| then if I require a further number this time when I click
| the command button the next number would appear in A2.
|
| I have the following macro running which works fine for
| the first part of this problem.
|
| Public Sub RCA()
| If IsEmpty(Range("A2").Value) Then
| Range("A2").Value = InputBox("Enter Starting
| Value")
| Else
| Range("A" & Rows.Count).End(xlUp).Offset(1,
| 0).Value = _
| Application.Max(Range("A:A")) + 1
| End If
| End Sub
|
| How can I adapt the above macro or use another in order
| to achieve the following in sheet 2 & 3.
|
| In sheet 2 I would like the same to happen except the
| batch number in cell A2, A3, A4 etc needs to start with
| the ref PCI followed by the first number for example
| (PCI1, PCI2, PCI3 and so on).
| I would like the same thing to happen in sheet 3 however
| the ref in cell A2 A3, A4 etc need to start with the ref
| PCICR followed by the first number for example (PCICR1,
| PCICR2, PCICR3 and so on).
|
| Hope you can understand this thanks for any help.
|
|


  #3   Report Post  
Monty
 
Posts: n/a
Default

This works a treat thanks very much

Monty
-----Original Message-----
If you put your prefix in some out of the way cell (I'm

using AA1, for the
first sheet this cell would be empty) then you could use

the same routine of
all worksheets:

Sub EnterNextNumber()
Dim LastCell As Range
Dim NextNum As Long
Dim Prefix As String
Prefix = Range("AA1").Value
Set LastCell = Range("A65536").End(xlUp)
If LastCell.Row = 1 Then
On Error Resume Next
NextNum = InputBox("Enter Starting Value")
If NextNum = 0 Then
Exit Sub ''No entry, cancel or non-numeric...
End If
Else
NextNum = Mid(LastCell.Value, Len(Prefix) + 1) +

1
End If
LastCell.Offset(1).Value = Prefix & NextNum
End Sub


--
Jim Rech
Excel MVP
"Monty" wrote in

message
...
|I am new to all this, so i will try and explian what I

am
| trying to achieve with this workbook.
| i want to be able to open this workbook with three
| worksheets, and all worksheets will have the following
| headings in A1(Batch No), B1(Date Sent), C1(Amount) &

D1
| (Date Paid).
| In sheet 1 when you click the command button I would

like
| to generate a numeric number which would appear in A2,
| then if I require a further number this time when I

click
| the command button the next number would appear in A2.
|
| I have the following macro running which works fine for
| the first part of this problem.
|
| Public Sub RCA()
| If IsEmpty(Range("A2").Value) Then
| Range("A2").Value = InputBox("Enter Starting
| Value")
| Else
| Range("A" & Rows.Count).End(xlUp).Offset(1,
| 0).Value = _
| Application.Max(Range("A:A")) + 1
| End If
| End Sub
|
| How can I adapt the above macro or use another in order
| to achieve the following in sheet 2 & 3.
|
| In sheet 2 I would like the same to happen except the
| batch number in cell A2, A3, A4 etc needs to start with
| the ref PCI followed by the first number for example
| (PCI1, PCI2, PCI3 and so on).
| I would like the same thing to happen in sheet 3

however
| the ref in cell A2 A3, A4 etc need to start with the

ref
| PCICR followed by the first number for example (PCICR1,
| PCICR2, PCICR3 and so on).
|
| Hope you can understand this thanks for any help.
|
|


.

Reply
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
Problem with Array Formulas and ISNUMBER Henrik Excel Worksheet Functions 1 February 10th 05 01:31 AM
Freeze Pane problem in shared workbooks JM Excel Discussion (Misc queries) 1 February 1st 05 01:04 AM
Printing Problem kimmyrt New Users to Excel 3 January 26th 05 09:55 PM
Row Autofit problem Excel 2003 Matthias Klaey Excel Discussion (Misc queries) 0 January 19th 05 06:33 PM
Paper Tray selection Problem, Michael Hoffmann Excel Discussion (Misc queries) 4 December 3rd 04 10:08 PM


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

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

About Us

"It's about Microsoft Excel"