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 9th, 2002, 08:31 AM   #1
wilkisa
Board Regular
 
Join Date: Apr 2002
Location: Decatur IL, USA
Posts: 494
Default

I am not sure how to begin but what I need is code that will compare the contents of two cells in one row. If the cells do not match, it will insert blank cells (not rows), moving the rightmost data down. Then it will begin the process of comparison again. I have a sample sheet that I would be happy to send to someone for testing.
wilkisa is offline   Reply With Quote
Old Apr 9th, 2002, 08:42 AM   #2
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

Not sure if it is what you want, but try the following code:

Do
If [a3] <> [b3] Then [b1].Insert Shift:=xlDown
Loop Until [a3] = [b3]

The code will test cells a3 and b3 if they are not the same then it will insert a blank cell in b1 pushing the data down. The code will stop when a3=b3. I also recommend adding in a counter so the code doesn't loop forever.

Dim counter As Integer
Do
If [a3] <> [b3] Then [b1].Insert Shift:=xlDown
counter = counter + 1
Loop Until [a3] = [b3] Or counter = 10


_________________
Hope this helps.
Kind regards, Al.

[ This Message was edited by: Al Chara on 2002-04-09 07:44 ]
Al Chara is offline   Reply With Quote
Old Apr 9th, 2002, 08:45 AM   #3
wilkisa
Board Regular
 
Join Date: Apr 2002
Location: Decatur IL, USA
Posts: 494
Default

Thanks, Al. Now how can I run this until the end of the data list?

Quote:
On 2002-04-09 07:42, Al Chara wrote:
Not sure if it is what you want, but try the following code:

Do
If [a3] <> [b3] Then [b1].Insert Shift:=xlDown
Loop Until [a3] = [b3]

The code will test cells a3 and b3 if they are not the same then it will insert a blank cell in b1 pushing the data down. The code will stop when a3=b3. I also recommend adding in a counter so the code doesn't loop forever.

Dim counter As Integer
Do
If [a3] <> [b3] Then [b1].Insert Shift:=xlDown
counter = counter + 1
Loop Until [a3] = [b3] Or counter = 10


_________________
Hope this helps.
Kind regards, Al.

[ This Message was edited by: Al Chara on 2002-04-09 07:44 ]
wilkisa is offline   Reply With Quote
Old Apr 9th, 2002, 08:50 AM   #4
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

You can set your counter equal to the number of cells that you want to do:

counter = Intersect(Columns("B"), ActiveSheet.UsedRange).Rows.Count

Or use the following:

Do
If [a3] <> [b3] Then [b1].Insert Shift:=xlDown
Loop Until [a3] = [b3] Or [b3] = ""

This loops until cell b3 is empty.

_________________
Hope this helps.
Kind regards, Al.

[ This Message was edited by: Al Chara on 2002-04-09 07:53 ]
Al Chara is offline   Reply With Quote
Old Apr 9th, 2002, 11:02 AM   #5
sjk
New Member
 
Join Date: Apr 2002
Posts: 14
Default

Al: This is just a question to help me learn since I am new to VBA and attempting to learn. The macro language you described above: it seems to me that cell A3 will never = B3 since the "B" column of data is being moved down each time. Unless there is an intermediate step where a user is entering new data into the cell B3, I am not sure conceptually how this would work. Perhaps you or Wilkisa could help. Thanks, SJK.
sjk is offline   Reply With Quote
Old Apr 9th, 2002, 11:09 AM   #6
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

sjk,

I assuming that there is data in the cells above. So everytime the macro loops it tests the value that was in the cell above. It inserts a blank cell at the top of the column, which pushes the cells down. To make this work properly, A3 and B3 should be changed to the cells at the bottom of the column. Does this answer your question?
__________________
Kind regards,

Al Chara
Al Chara is offline   Reply With Quote
Old Apr 9th, 2002, 11:25 AM   #7
sjk
New Member
 
Join Date: Apr 2002
Posts: 14
Default

Thanks, Al. Yes, seems obvious once you explained it! (Kept thinking that we were at the top of the column).
sjk is offline   Reply With Quote
Old Apr 9th, 2002, 01:03 PM   #8
wilkisa
Board Regular
 
Join Date: Apr 2002
Location: Decatur IL, USA
Posts: 494
Default

Al, I am still very unclear on how to make this work. I have a table of static data, col. A-E and rows 2-168. Row A is a shipping number. Now in col. G-K I have 59 rows of data beginning in row 2 also. Col. G is the shipping number. What I need is to compare G2 to A2. If G2 <> A2, then insert blank cells in G2-K2, move the data down and compare now G3 to A3. If G3=A3, then leave it alone, move cursor to G4 and start comparing again until all of the data in G-K has been placed in the correct row to correspond with the data in Col. A. Does this make sense?

I am very green with VB and need some step by step handholding.

Thanks!!!
wilkisa is offline   Reply With Quote
Old Apr 9th, 2002, 01:13 PM   #9
Al Chara
MrExcel MVP
 
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
Default

Send me your workbook.
Al Chara is offline   Reply With Quote
Old Apr 9th, 2002, 01:18 PM   #10
wilkisa
Board Regular
 
Join Date: Apr 2002
Location: Decatur IL, USA
Posts: 494
Default

Bless you, Al. Where should I send it? I have been unable to find a way to attach it to this site.

wilkisa 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 12:58 AM.


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