Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 109
Default Help with some sheet code

I have the following code which adds an ID number to rows of data entered
onto a certain sheet. The number is entered into column A when an entry is
made into column B.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 And Target.Count = 1 Then
If IsEmpty(Cells(Target.Row, 1)) Then
Application.EnableEvents = False
Target.Offset(0, -1).Value = Target.Row - 1
End If
End If
Application.EnableEvents = True
End Sub

This works fine but I have found myself in the situation where 100's of rows
of data are copied to the sheet, an ID number is not created when I do this.
Is it possible to amend the existing code to accomodate both methods of data
entry onto the sheet?

Thanks in advance.

Gareth

PS
Is there a need for a error handler?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Help with some sheet code



Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng as Range, rng1 as Range
If Target.Column = 2 And Target.Count = 1 Then
Application.EnableEvents = False
set rng = Range(cells(2,1),Cells(rows.count,1).End(xlup))
if Intersect(rng, cells(1,1)) is Nothing then
set rng1 = rng.specialcells(xlblanks)
rng1.Formula = "=row()-1"
rng.formula = rng.value
else
Target.Value = Target.row-1
end if
End If
Application.EnableEvents = True
End Sub

Regards,
Tom Ogilvy


Gareth wrote in message
...
I have the following code which adds an ID number to rows of data entered
onto a certain sheet. The number is entered into column A when an entry

is
made into column B.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 And Target.Count = 1 Then
If IsEmpty(Cells(Target.Row, 1)) Then
Application.EnableEvents = False
Target.Offset(0, -1).Value = Target.Row - 1
End If
End If
Application.EnableEvents = True
End Sub

This works fine but I have found myself in the situation where 100's of

rows
of data are copied to the sheet, an ID number is not created when I do

this.
Is it possible to amend the existing code to accomodate both methods of

data
entry onto the sheet?

Thanks in advance.

Gareth

PS
Is there a need for a error handler?




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
Hide a sheet using code LJP Excel Discussion (Misc queries) 12 July 12th 08 03:58 PM
Sheet Code Robert B. Excel Worksheet Functions 2 November 7th 07 07:00 PM
Sheet Name Changes how do i code for that Sonic Excel Worksheet Functions 0 July 10th 07 08:58 PM
VB code to copy sheet format to another sheet ASU Excel Discussion (Misc queries) 12 August 10th 06 02:37 AM
Sheet Protection and VBA Code TheRobsterUK Excel Discussion (Misc queries) 1 May 27th 05 05:18 PM


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