Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default AutoFill Help Please

Hello,

Could someone please help with the following Excel 2003 AutoFill
problem?

I am trying to create a macro so that when a new row of data is added to
my worksheet, the formula in column J is automatically AutoFilled down
to the last row of data. I only add one row of data at a time. So, I
am basically only AutoFilling down one row at a time.

The worksheet is named: SP155_Register

The is a header row at row 2

The data rows start at row 3

The cell at J2 is called: STATUS

If anyone can please help, it would be greatly appreciated.

Thanks,

Chris.

Live Long and Prosper :-)

*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default AutoFill Help Please

right click on the worksheet tab and select view code. Paste in code like
this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim lrowA As Long, lrowj As Long
lrowA = Cells(Rows.Count, "A").End(xlUp).Row
lrowj = Cells(Rows.Count, "J").End(xlUp).Row
If lrowj < lrowA Then
For i = lrowj + 1 To lrowA
Cells(i, "J").FillDown
Next
End If
End Sub


--
Regards,
Tom Ogilvy


"Chris Hankin" wrote:

Hello,

Could someone please help with the following Excel 2003 AutoFill
problem?

I am trying to create a macro so that when a new row of data is added to
my worksheet, the formula in column J is automatically AutoFilled down
to the last row of data. I only add one row of data at a time. So, I
am basically only AutoFilling down one row at a time.

The worksheet is named: SP155_Register

The is a header row at row 2

The data rows start at row 3

The cell at J2 is called: STATUS

If anyone can please help, it would be greatly appreciated.

Thanks,

Chris.

Live Long and Prosper :-)

*** Sent via Developersdex http://www.developersdex.com ***

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default AutoFill Help Please

This is a tricky routine. Had to consider deleting rows as well as adding
row. The function doesn't do anythin if you add or delete row 3.

Private Sub Worksheet_Change(ByVal Target As Range)


Const StartCell = "J3"

' Prevent endless loops - changing cell causes
' routine to execute recursively
' Target address for insert row looks like $8:$8
If InStr(Target.Address, ":") < 0 Then


LeftAddress = Left(Target.Address, InStr(Target.Address, ":") - 1)

' row 3 exit routine because we don't know what to do
If (StrComp(Mid(LeftAddress, 2), "3") = 0) Then Exit Sub

'If column exit routine
If (IsNumeric(Mid(LeftAddress, 2)) = False) Then Exit Sub


RightAddress = Mid(Target.Address, InStr(Target.Address, ":") + 1)
If StrComp(LeftAddress, RightAddress) = 0 Then


RowCount = 0
Do While (1)
Destination1 = Range(StartCell). _
Offset(rowoffset:=RowCount + 1, columnoffset:=0)
Destination2 = Range(StartCell). _
Offset(rowoffset:=RowCount + 2, columnoffset:=0)

'thses statement are needed if rows are deleted
MyError = IsError(Destination) Or IsError(Destination2)
If MyError = False Then

If (Destination1 = "") And (Destination2 = "") Then

Exit Do

End If
End If

Range(StartCell). _
Offset(rowoffset:=RowCount, columnoffset:=0).Copy _
Destination:=Range(StartCell).Cells. _
Offset(rowoffset:=RowCount + 1, columnoffset:=0)

RowCount = RowCount + 1
Loop
End If



End If




End Sub


"Chris Hankin" wrote:

Hello,

Could someone please help with the following Excel 2003 AutoFill
problem?

I am trying to create a macro so that when a new row of data is added to
my worksheet, the formula in column J is automatically AutoFilled down
to the last row of data. I only add one row of data at a time. So, I
am basically only AutoFilling down one row at a time.

The worksheet is named: SP155_Register

The is a header row at row 2

The data rows start at row 3

The cell at J2 is called: STATUS

If anyone can please help, it would be greatly appreciated.

Thanks,

Chris.

Live Long and Prosper :-)

*** Sent via Developersdex http://www.developersdex.com ***

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default AutoFill Help Please

Thanks Tom and Joel,

Due to time differences in Australia, I will let you know how I went
with your codes. Thanks again for all your efforts - very much
appreciated.

Cheers,

Chris.

Live Long and Prosper :-)

*** Sent via Developersdex http://www.developersdex.com ***
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default AutoFill Help Please

Hello Tom and Joel,

Your codes worked very well thanks.

Cheers,

Chris.



*** Sent via Developersdex http://www.developersdex.com ***
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
Autofill Until uberathlete Excel Discussion (Misc queries) 1 November 10th 05 04:08 PM
Autofill until uberathlete Excel Discussion (Misc queries) 1 November 9th 05 06:01 PM
Autofill: Need to autofill one week block, (5) weekday only into cells. dstock Excel Discussion (Misc queries) 1 June 17th 05 08:21 PM
Autofill last row Duncan_J Excel Programming 3 August 27th 04 11:11 PM
Q. Autofill question: Can I autofill alpha characters like I can numbers? George[_22_] Excel Programming 5 August 7th 04 10:33 AM


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