Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Mark
 
Posts: n/a
Default Command button

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
  #2   Report Post  
JE McGimpsey
 
Posts: n/a
Default

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?

In article ,
"Mark" wrote:

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

  #3   Report Post  
mark
 
Posts: n/a
Default

I would like the numbers to start in A2 then A3 Then A4
etc

thanks
-----Original Message-----
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?

In article ,
"Mark" wrote:

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

.

  #4   Report Post  
JE McGimpsey
 
Posts: n/a
Default

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



In article ,
"mark" wrote:

I would like the numbers to start in A2 then A3 Then A4
etc

  #5   Report Post  
 
Posts: n/a
Default

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

Thanks once again
mark

-----Original Message-----
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



In article ,
"mark" wrote:

I would like the numbers to start in A2 then A3 Then

A4
etc

.

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



All times are GMT +1. The time now is 12:58 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"