Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
don don is offline
external usenet poster
 
Posts: 8
Default Finding data of one sheet in another sheet

I am using a similiar subroutine finding data in one sheet that
matches that in another sheet.
I find it very confusing and after lots of trial and error get the
routines to work but don't exactly understand why.
If I don't have line 6(activate) prior to setting range DRange
I get an error.
If I don't have line 8 (activate) prior to the For Each c line
I get an error.
yet lines 2, 3, 5 seem to work fine without first
activating the sheet.
Yet once I get into the For/If section (lines 9 - 18) I don't seem to
have to use the .Activate command. see line 10 is commented out.
Why is that?
also is there a difference between Worksheets and Sheets?
sometimes I think they are the same, other times I am not so sure.

Also what is the difference between .activate and .select.
I notice using hidden sheets activate works and select does not.
In the routine below, excel ends up showing test2 on the screen,
although it has never been selected.
Thanks
Don



1 Sub test()
2 Worksheets("test3").Columns(2).ClearContents
3 Worksheets("test3").Cells(11, 1).ClearContents
4
5 Worksheets("test3").Cells(11, 1) = Worksheets("test2").Cells(1, 1)
6 Sheets("test3").Activate
7 Set DRange = Worksheets("test3").Range(Cells(1, "a"), Cells(7,
"a"))
8 Sheets("test2").Activate
9 For Each c In Worksheets("test2").Range(Cells(1, "a"), Cells(7,
"a"))
10 'Worksheets("test3").Activate
11 Set D = DRange.Find(c, , , xlWhole)
12
13 If Not D Is Nothing Then
14 'MsgBox D & " " & D.Row
15 Worksheets("test3").Cells(D.Row, 2) = c
16 Else
17 Worksheets("test3").Cells(10, 2) = c & " was not found"
18 End If
19 L: Next
20 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
finding data in the same sheet Barry Excel Discussion (Misc queries) 1 February 12th 09 12:37 PM
finding data in the same sheet Barry Excel Discussion (Misc queries) 1 February 11th 09 01:46 AM
finding data in the same sheet Barry Excel Discussion (Misc queries) 1 February 11th 09 01:39 AM
finding data in the same sheet Barry Excel Discussion (Misc queries) 1 February 9th 09 09:18 AM
finding data in the same sheet Barry Excel Discussion (Misc queries) 2 February 9th 09 12:43 AM


All times are GMT +1. The time now is 02:59 PM.

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"