LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default look in second worksheet if value not found

Hi everyone,
Using email addresses in Workbook1, I need to find those email
addresses in Workbook2, then copy/paste, the 8 cells next to the found
cells back to Workbook1. The macro goes down each cell until it hits
a blank one a stops. It's my first macro ever so pardon if it's
ugly. If you see something where you go, "WTF was he doing?" let me
know what a better way is. I appreciate the feedback.

My macro uses the FIND method and I want it to look at worksheet 2 if
it doesn't find it. Something like

If foundcell is nothing then
(look in worksheet two instead)
else
(do the normal stuff)

I tried creating a second range similar to oRng except with
Worksheets(2) and using that in the "If" statement but it didn't
work. Also, I'll need some sort of On Error Resume Next if the value
isn't found in either worksheets.

Here's my current code:

Option Explicit
Option Compare Text
Sub PasteValues()
Dim aRng as Range
Dim oRng as Range
Dim rfoundCell as Range
Dim count as Byte
Const CELLNUM as Byte = 8 'the number of cells to copy, I want
this flexible
set oRng = Workbooks("sourcesheet.xls").Worksheets(1).Range(" A:H")
set aRng = ActiveCell

Do While aRng.Value < ""
On Error Resume Next
Set rFoundCell = oRng.Find(aRng.Value, LookIn:=xlValues)
count = 1
Do Until count = CELLNUM
aRng.Offset(0, count).Value = rfoundCell.Offset(0,
count).Value
count = count + 1
Loop
Set aRng = aRng.Offset(1,0)
Loop
set aRng = Nothing
set rfoundCell = Nothing
set oRng = Nothing

End Sub

Thanks a bunch. As an aside, if anyone has a really good book
suggestion, I'm a taker. I read online help and most of Excel 2003
programming Inside and Out and I guess this is as far as it got me.

 
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
when I reopen the excel worksheet I found that the amount changed mary Excel Discussion (Misc queries) 1 September 8th 08 07:04 AM
Return worksheet name containing value found in 3D reference funct PKK Excel Worksheet Functions 8 November 15th 07 04:00 PM
worksheet subroutine causes Compile error: Not found when on User Jim Brownson Excel Programming 3 August 9th 06 07:15 PM
How do I know on which worksheet an item is found? Talar Excel Discussion (Misc queries) 2 June 21st 06 11:56 AM
not found Nathan[_4_] Excel Programming 1 June 25th 04 05:26 AM


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