Command button

M

Mark

Hi

If I have the following macro running in a workbook and I
add titles to cells A1 B1 C1 & D1 the first number will
appear in cell A2 when I click the command button however
the next number appear in cells D3, D4, D5 etc ?
Any suggestions welcome.


Option Explicit
Sub RCA()

ActiveSheet.UsedRange
If Range("A2").Value = "" Then
Range("A2").Value = InputBox("Enter starting
value")
Else
Range("A2").SpecialCells
(xlCellTypeLastCell).Offset(1, 0).Value =
Application.WorksheetFunction.Max(Range("A:A")) + 1
End If
End Sub


Thanks

Mark
 
J

JE McGimpsey

By using SpecialCells(xlCellTypeLastCell) you're going to the last
"used" cell (whether with a value or formatting) - i.e, the cell in the
farthest right used column (D) and the farthest down used row (e.g, 2).
It sounds like you've already got something in D2, so the .Offset(1, 0)
will put the new data in D3.

Where do you want the number to appear?
 
J

JE McGimpsey

ONe way:

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

this assumes that there's nothing in column A below the cells you're
filling
 
G

Guest

Thanks for this.
if i wanted to add some letters before the number how
would i go about this.

Thanks once again
mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top