Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
when I reopen the excel worksheet I found that the amount changed | Excel Discussion (Misc queries) | |||
Return worksheet name containing value found in 3D reference funct | Excel Worksheet Functions | |||
worksheet subroutine causes Compile error: Not found when on User | Excel Programming | |||
How do I know on which worksheet an item is found? | Excel Discussion (Misc queries) | |||
not found | Excel Programming |