MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Apr 12th, 2002, 11:34 AM   #1
Man of Action
New Member
 
Join Date: Apr 2002
Posts: 15
Default

Well here is my problem. I want to copy a value from a worksheet and paste it into find on a different worksheet. I want to find the value on the second worksheet, copy the three cells next to it and change to the first worksheet and paste them into it.

Everything seems to work fine except when I past my value into the find. I want to be able to loop it but when I run it twice it finds the original value all the time instead of the new copied one?!?!?

If anyone can see what is wrong here please let me know it would be greatly appreciated.

Man of Action is offline   Reply With Quote
Old Apr 12th, 2002, 11:37 AM   #2
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

Could you post your code? That would help.
Cosmos75 is offline   Reply With Quote
Old Apr 12th, 2002, 11:46 AM   #3
Man of Action
New Member
 
Join Date: Apr 2002
Posts: 15
Default

I guess I should have thought of that. Here is the code to my question:

ActiveCell.Offset(0, -3).Range("A1").Select
Selection.Copy
Windows("Test2.xls").Activate
Cells.Find(What:="714491", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
ActiveCell.Offset(0, 1).Range("A1:C1").Select
Application.CutCopyMode = False
Selection.Copy
ActiveCell.Offset(0, -1).Range("A1").Select
Windows("Test1.xls").Activate
ActiveCell.Offset(0, 3).Range"A1").Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Range"A1").Select


Man of Action is offline   Reply With Quote
Old Apr 12th, 2002, 12:52 PM   #4
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

Quote:
On 2002-04-12 10:46, Man of Action wrote:
I guess I should have thought of that. Here is the code to my question:

ActiveCell.Offset(0, -3).Range("A1").Select
Selection.Copy
Windows("Test2.xls").Activate
Cells.Find(What:="714491", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
ActiveCell.Offset(0, 1).Range("A1:C1").Select
Application.CutCopyMode = False
Selection.Copy
ActiveCell.Offset(0, -1).Range("A1").Select
Windows("Test1.xls").Activate
ActiveCell.Offset(0, 3).Range"A1").Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Range"A1").Select


Well the part

Cells.Find(What:="714491", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _

is always going to look for 714491, which I assume is the value of A1.

You need to use

ActiveCell.Offset(0, -3).Range("A1").Select
FindValue = Selection.Value
Windows("Test2.xls").Activate
Cells.Find(What:=FindValue, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate
ActiveCell.Offset(0, 1).Range("A1:C1").Select
Application.CutCopyMode = False
Selection.Copy
ActiveCell.Offset(0, -1).Range("A1").Select
Windows("Test1.xls").Activate
ActiveCell.Offset(0, 3).Range"A1").Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Range"A1").Select

EDIT: What range are you using that containns the values you want to find? I could try to help with the looping part.

Also, I don't understand why you have

ActiveCell.Offset(0, -3).Range("A1").Select

instead of just

Range(ActiveCell.Offset(0, 1), ActiveCell.Offset(0, 3)).Select

[ This Message was edited by: Cosmos75 on 2002-04-12 12:10 ]
Cosmos75 is offline   Reply With Quote
Old Apr 12th, 2002, 12:55 PM   #5
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default

Hi,

Rewrite your code so you don't select anything. Is Test1.xls the workbook where you have this procedure, or are you transferring a value from test2 to test1 after you have copied the first part (controlled from a 3rd workbook)?

In any event, I think the following will do what you want...

------------------
Sub test()
Dim FoundCell As String

FoundCell = Workbooks("Test2.xls").Sheets("Sheet1").Cells.Find(What:="714491", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Address(False, False)

ActiveCell.Offset(0, -3).Copy Workbooks("Test2.xls").Sheets("Sheet1").Range(FoundCell).Offset(0, 1).Resize(, 3)

ActiveCell = Workbooks("Test2.xls").Sheets("Sheet1").Range(FoundCell).Value
End Sub
----------------

HTH,
Jay
Jay Petrulis is offline   Reply With Quote
Old Apr 12th, 2002, 01:02 PM   #6
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

Jay,

I think Man of Action record a macro by way of selecting a cell, copying the value and then choosing Find and pasting the value in the find inputbox. When you record a macro it enters the value copied but doesn't take into account if the value changes. Whatever value was copied originally when the macro was recorded is the one that will always be used.
Cosmos75 is offline   Reply With Quote
Old Apr 15th, 2002, 10:33 AM   #7
Man of Action
New Member
 
Join Date: Apr 2002
Posts: 15
Default

Thanks for your help guys.

Cosmos,

I tried that change you suggested but when I run the macro the find does not work. It doesn't look for anything?

Confused,
M of A

Man of Action is offline   Reply With Quote
Old Apr 15th, 2002, 10:39 AM   #8
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

Kinda odd, it worked for me.

Try opening the VB Editor and running through the macro line by line by using F8. Let me know what's where the error occurs.
Cosmos75 is offline   Reply With Quote
Old Apr 15th, 2002, 10:40 AM   #9
Cosmos75
Board Regular
 
Join Date: Feb 2002
Location: Tulsa, OK
Posts: 354
Default

My post showed up as

ActiveCell.Offset(0, -1).Range("A1").Select
Windows("Test1.xls").Activate
ActiveCell.Offset(0, 3).Range"A1").Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Range"A1").Select

Should be

ActiveCell.Offset(0, -1).Range("A1").Select
Windows("Test1.xls").Activate
ActiveCell.Offset(0, 3).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Range("A1").Select
Cosmos75 is offline   Reply With Quote
Old Apr 15th, 2002, 02:26 PM   #10
Man of Action
New Member
 
Join Date: Apr 2002
Posts: 15
Default

I got it working. Thanks.

If it can't find the value it just craps out. Is there a way to continue?

Man of Action is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 02:18 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes