Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Change event code Find .Activate does not activate Target.value

If I enter a number on sheet 1 I want to know if it exist on any of the sheets in the array.

As is, if I enter 2468 on sheet 1 it runs through the array sheets but does not activate the number 2468 on sheet 4 which I am using for the test. The other sheets have no matching number in my test.

I can un-comment the MsgBox and it verifies "CheckNum" as the sheets are tested, but nothing happens on sheet 4 where there is indeed a true match to CheckNum.

If I run the Macro 8 sub in sheet 4 module it selects the 2468 as I would expect from both it and the change event.

If I try this line I get an yellow highlight error. Doesn't want the . in front of UsedRange.

.UsedRange.Find(What:=CheckNum).Activate

My ultimate goal is to produce a MsgBox on sheet 1 telling the user that the number exists on ...Sheet 3 $D:$6, for example or "Not Found".

Gotta get past this elusive Find code first.

Thanks,
Howard

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

Dim CheckNum As Long
Dim varSheets As Variant
Dim i As Long

CheckNum = Target.Value

varSheets = Array("Sheet2", "Sheet3", "Sheet4")

For i = LBound(varSheets) To UBound(varSheets)
With Sheets(varSheets(i))
'MsgBox CheckNum
UsedRange.Find(What:=CheckNum).Activate

End With
Next
End Sub



Option Explicit

Sub Macro8()
Dim CheckNum As Long
CheckNum = 2468
With Sheets("Sheet4")
UsedRange.Find(What:=CheckNum).Activate
End With
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Change event code Find .Activate does not activate Target.value

Hi Howard,

Am Sat, 23 Nov 2013 22:46:23 -0800 (PST) schrieb Howard:

.UsedRange.Find(What:=CheckNum).Activate


set c = .UsedRange(...

try:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim CheckNum As Long
Dim varSheets As Variant
Dim i As Long
Dim c As Range

CheckNum = Target.Value

varSheets = Array("Sheet2", "Sheet3", "Sheet4")

For i = LBound(varSheets) To UBound(varSheets)
With Sheets(varSheets(i))
Set c = .UsedRange.Find(What:=CheckNum, LookIn:=xlValues)
If Not c Is Nothing Then
Application.Goto c
End If
End With
Next
End Sub


Regards
Claus B.
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Change event code Find .Activate does not activate Target.value

Hi again,

Am Sun, 24 Nov 2013 09:38:51 +0100 schrieb Claus Busch:

If Not c Is Nothing Then
Application.Goto c
End If


change it to:

If Not c Is Nothing Then
Application.Goto c
Exit For
End If


Regards
Claus B.
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Change event code Find .Activate does not activate Target.value



try:



Private Sub Worksheet_Change(ByVal Target As Range)



Dim CheckNum As Long

Dim varSheets As Variant

Dim i As Long

Dim c As Range



CheckNum = Target.Value



varSheets = Array("Sheet2", "Sheet3", "Sheet4")



For i = LBound(varSheets) To UBound(varSheets)

With Sheets(varSheets(i))

Set c = .UsedRange.Find(What:=CheckNum, LookIn:=xlValues)

If Not c Is Nothing Then

Application.Goto c

End If

End With

Next

End Sub





Regards

Claus B.



Works great, I did make the small change you posted.

Thank Claus.

Howard
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Change event code Find .Activate does not activate Target.value

Hi Howard,

Am Sat, 23 Nov 2013 22:46:23 -0800 (PST) schrieb Howard:

If I try this line I get an yellow highlight error. Doesn't want the . in front of UsedRange.

.UsedRange.Find(What:=CheckNum).Activate


no, the error comes because you only can select or activate a cell on a
active sheet. You first have to activate the sheet then you can activate
the cell.


Regards
Claus B.
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2


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
VBA code to find first blank cell in a column and activate it Wes_A[_2_] Excel Programming 5 April 4th 23 12:54 PM
closing another file by code causes failure to run workbook activate event [email protected] Excel Programming 2 July 12th 12 02:07 PM
Reliably activate PowerPoint, do something, Activate Excel Barb Reinhardt Excel Programming 1 December 4th 08 09:42 PM
Event Macro - On Cell Activate - Change Cell Format [email protected][_2_] Excel Programming 7 November 7th 07 03:36 AM
Cell value Change Event - Need to activate macro Listbox use in Excel Excel Programming 4 July 26th 05 08:28 PM


All times are GMT +1. The time now is 10:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"