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 Mar 9th, 2002, 12:32 PM   #1
Guest
 
Posts: n/a
Default

So far i have this code.
It is supposed to do this:

1. Go to a user defined sheet
2. search down a column finding a specific piece of text
3.when it finds the right cell. use the offset command to find pieces of data
4.copy and paste this data to another sheet
5. and add all accumulated data to the bottom of a table.
6. and then carry on searching through that column for more of the same criteria

Dim List As Object
Dim Cell1 As Object
Set List = Range((Range("MonthCHoice").Value) & 1)
Sheets(Range("MonthCHoice").Value).Select
For Each Cell1 In List
If Cell1 = Range("CourseName") Then
ActiveCell.Copy
Range("G7").Select
Selection.Copy
Sheets("Lists").Select
Range("Course45").Select
ActiveSheet.Paste
Sheets("January").Select
ActiveCell.Offset(0, 1).Range("A1").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Lists").Select
Range("Attendees45").Select
ActiveSheet.Paste
Sheets("January").Select
ActiveCell.Offset(0, -6).Range("A1").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Lists").Select
Range("Date45").Select
ActiveSheet.Paste
Range("Row").Select
Selection.Copy
Range("Dummy").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
Sheets(Range("MonthCHoice").Value).Select
End If
Next

The problems that i am having are that. It finds the first data okay. Then it copies it like i want it to. Then say i have five rows of the same criteria, it would create five rows onto the table, but use the same data for each, instead of using its own data. (also when there are four rows of the same criteria, four rows of the same data would be added). This is related to my earlier post, because the final table would be the range I want to name. Does anyone see any errors or anything wrong with the code. I have been trying to do this all day!
  Reply With Quote
Old Mar 9th, 2002, 12:32 PM   #2
waggy30
New Member
 
Join Date: Mar 2002
Location: England
Posts: 46
Default

It was me who posted this
waggy30 is offline   Reply With Quote
Old Mar 9th, 2002, 12:59 PM   #3
Barrie Davidson
MrExcel MVP
 
Barrie Davidson's Avatar
 
Join Date: Feb 2002
Location: Winnipeg
Posts: 2,330
Default

What is the address of the active cell on the sheet named "January"? Does this ever change?
__________________
Barrie Davidson

"You're only given a little spark of madness. You mustn't lose it." - Robin Williams
Barrie Davidson is offline   Reply With Quote
Old Mar 9th, 2002, 01:23 PM   #4
waggy30
New Member
 
Join Date: Mar 2002
Location: England
Posts: 46
Default

Thanks, I think you just found the problem. The active cell is meant to refer to the cell1 object. How would I refer to that?
waggy30 is offline   Reply With Quote
Old Mar 9th, 2002, 01:49 PM   #5
Barrie Davidson
MrExcel MVP
 
Barrie Davidson's Avatar
 
Join Date: Feb 2002
Location: Winnipeg
Posts: 2,330
Default

Quote:
On 2002-03-09 12:23, waggy30 wrote:
Thanks, I think you just found the problem. The active cell is meant to refer to the cell1 object. How would I refer to that?
I hope you don't mind, but I made your code a little more efficient. One thing I have learned is: if you can eliminate "selecting" anything your code will be that much quicker.

Try this code (note, I did not test it so I'll bet you'll find something wrong. Difficult to test without data):

Dim List As Object
Set List = Range((Range("MonthCHoice").Value) & 1)
Sheets(Range("MonthCHoice").Value).Select
For Each c In List
If c = Range("CourseName") Then
Range("G7").Copy Destination:=Sheets("Lists").Range("Course45")
Sheets("January").Select
ActiveCell.Offset(0, 1).Copy _
Destination:=Sheets("Lists").Range("Attendees45")
ActiveCell.Offset(0, -6).Copy _
Destination:=Sheets("Lists").Range("Date45")
Range("Row").Copy _
Destination:=Range("Dummy").End(xlDown).Offset(1, 0)
Sheets(Range("MonthCHoice").Value).Select
End If
Next c


The reason I was asking for what the active cell's address was in the sheet named "January", was to change the code so you didn't need to activate that sheet. If you can tell me how the cell is activated, maybe we can take out the step activating that sheet.

If you do encounter errors just let me know and we can tweak the code.

Regards,
__________________
Barrie Davidson

"You're only given a little spark of madness. You mustn't lose it." - Robin Williams
Barrie Davidson is offline   Reply With Quote
Old Mar 9th, 2002, 02:19 PM   #6
waggy30
New Member
 
Join Date: Mar 2002
Location: England
Posts: 46
Default

Once again thanks. I tweaked the code and it worked. The final code is

Dim List As Object
Dim c As Object
Set List = Range((Range("MonthCHoice").Value) & "1")
Sheets(Range("MonthCHoice").Value).Select
For Each c In List
If c = Range("CourseName") Then
c.Copy Destination:=Sheets("Lists").Range("Course45")
Sheets(Range("MonthCHoice").Value).Select
c.Offset(0, 2).Copy _
Destination:=Sheets("Lists").Range("Attendees45")
c.Offset(0, -5).Copy _
Destination:=Sheets("Lists").Range("Date45")
Sheets("Lists").Select
Range("Row").Copy _
Destination:=Range("Dummy").End(xlDown).Offset(1, 0)
Sheets(Range("MonthCHoice").Value).Select
End If
Next c
Sheets("Lists").Select
Range("F25", Range("H65536").End(xlUp).Address).Name = "RowSource"
CourseViewer.Show

Thanks again
waggy30 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:59 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