Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 76
Default Only finds first Occurrence

Hello from Steved

Below works fine if I run it as a straight macro
ie sub Test()

Question when I ran it it would only do the first occurence
City and put city in all the others please what is required
for this to work.

Thankyou.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Const sFIND As String = "TOTAL SHIFT HOURS"
Dim vArr As Variant
Dim rFound As Range
Dim nCount As Long

vArr = Array
("City", "Roskill", "Papakura", "Wiri", "Shore", "Orewa", "
Swanson", "Panmure")
nCount = 0
Set rFound = Cells.FIND( _
What:=sFIND, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)
Do While Not rFound Is Nothing And nCount <= UBound
(vArr)
rFound.Value = vArr(nCount)
nCount = nCount + 1
Set rFound = Cells.FindNext(after:=rFound)
Loop


End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Only finds first Occurrence

Everytime you make a change in the change event, you fire another change
event. I suspect Excel just quits after awhile, overcome by frustration.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Const sFIND As String = "TOTAL SHIFT HOURS"
Dim vArr As Variant
Dim rFound As Range
Dim nCount As Long

vArr = Array("City", "Roskill", "Papakura", _
"Wiri", "Shore", "Orewa", "Swanson", "Panmure")
nCount = 0
Application.EnableEvents = False
On Error goto ErrHandler
Set rFound = Cells.FIND( _
What:=sFIND, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)
Do While Not rFound Is Nothing _
And nCount <= UBound (vArr)
rFound.Value = vArr(nCount)
nCount = nCount + 1
Set rFound = Cells.FindNext(after:=rFound)
Loop

ErrHandler:
Application.EnableEvents = True
End Sub

--
Regards,
Tom Ogilvy


"Steved" wrote in message
...
Hello from Steved

Below works fine if I run it as a straight macro
ie sub Test()

Question when I ran it it would only do the first occurence
City and put city in all the others please what is required
for this to work.

Thankyou.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Const sFIND As String = "TOTAL SHIFT HOURS"
Dim vArr As Variant
Dim rFound As Range
Dim nCount As Long

vArr = Array
("City", "Roskill", "Papakura", "Wiri", "Shore", "Orewa", "
Swanson", "Panmure")
nCount = 0
Set rFound = Cells.FIND( _
What:=sFIND, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)
Do While Not rFound Is Nothing And nCount <= UBound
(vArr)
rFound.Value = vArr(nCount)
nCount = nCount + 1
Set rFound = Cells.FindNext(after:=rFound)
Loop


End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 76
Default Only finds first Occurrence

Hello Tom

Thanks very much.

-----Original Message-----
Everytime you make a change in the change event, you fire

another change
event. I suspect Excel just quits after awhile, overcome

by frustration.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Const sFIND As String = "TOTAL SHIFT HOURS"
Dim vArr As Variant
Dim rFound As Range
Dim nCount As Long

vArr = Array("City", "Roskill", "Papakura", _
"Wiri", "Shore", "Orewa", "Swanson", "Panmure")
nCount = 0
Application.EnableEvents = False
On Error goto ErrHandler
Set rFound = Cells.FIND( _
What:=sFIND, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)
Do While Not rFound Is Nothing _
And nCount <= UBound (vArr)
rFound.Value = vArr(nCount)
nCount = nCount + 1
Set rFound = Cells.FindNext(after:=rFound)
Loop

ErrHandler:
Application.EnableEvents = True
End Sub

--
Regards,
Tom Ogilvy


"Steved" wrote in

message
...
Hello from Steved

Below works fine if I run it as a straight macro
ie sub Test()

Question when I ran it it would only do the first

occurence
City and put city in all the others please what is

required
for this to work.

Thankyou.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Const sFIND As String = "TOTAL SHIFT HOURS"
Dim vArr As Variant
Dim rFound As Range
Dim nCount As Long

vArr = Array

("City", "Roskill", "Papakura", "Wiri", "Shore", "Orewa", "
Swanson", "Panmure")
nCount = 0
Set rFound = Cells.FIND( _
What:=sFIND, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)
Do While Not rFound Is Nothing And nCount <= UBound
(vArr)
rFound.Value = vArr(nCount)
nCount = nCount + 1
Set rFound = Cells.FindNext(after:=rFound)
Loop


End Sub




.

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
formula the finds value of cell above vpantus Excel Discussion (Misc queries) 2 November 9th 10 01:57 PM
lookup only finds #n/a's Janis Excel Discussion (Misc queries) 4 July 26th 07 11:02 PM
finds and concatenate vikram Excel Programming 3 May 20th 04 02:02 PM
Multi-worksheet finds Andy Westlake Excel Programming 1 February 10th 04 06:21 PM
Find finds nothing, and errors Chris M.[_3_] Excel Programming 1 August 25th 03 06:31 PM


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