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 25th, 2002, 10:03 AM   #1
susanna
Board Regular
 
Join Date: Apr 2002
Posts: 58
Default

Hi -
I have a report that downloads to excel with information in columns:

account name code tel #
12345 john pe 5551212
12345 joe sl 5551213
12345 jane ca 5551214
6789 bill sl 4441111
6789 brenda ca 4441112
6789 brad pe 4441113

and I need to move everything into rows like this:

account name code tel# name code tel#
12345 jane ca 5551212 joe sl 5551213...
6789 brenda ca 4441112 bill sl 4441111

Is there a way to automate this so that I don't have to cut and paste everything...

I am new at this posting thing, so i hope this comes out right!!!

~s


susanna is offline   Reply With Quote
Old Apr 25th, 2002, 10:57 AM   #2
susanna
Board Regular
 
Join Date: Apr 2002
Posts: 58
Default

ok... not sure if my original post made enough sense...sorry...let me try again...

anyway... I have this download, and it comes out with the following headings:
account (A1), name (B1), code (C1) and tel# (D1). So A2-A5 could all be the same account with B2-B5 having the names of the various people working on that account. I need to change it so that there is only one row per account, and the rest of the information will be put into that row. ie: Row 2, A2 will contain the account number, Row 2, B2 will contain a name, Row 2, C2 will contain the corresponding code to the name in B2, Row 2, D2 will contain the tel #, Row 2, E2 will contain the next name associated with that account, Row 2,F2 will contain the code associated with the name in E2, Row 2, G2 will contain the tel# and so on and so forth.
So rather than having four rows and four columns for each account, I need to have 1 row and 12 columns for each account.

Is this any clearer? Probably not... I apologize... but if anyone can figure out what the heck i am talking about, I would be hugely grateful!

~s
susanna is offline   Reply With Quote
Old Apr 25th, 2002, 11:56 AM   #3
bergy
Board Regular
 
Join Date: Apr 2002
Posts: 112
Default

Hi,

Is it okay to post the new data on a new spreadsheet, or does it have to go on existing sheet? Is there a limit on the number of names associated with an account?

bergy is offline   Reply With Quote
Old Apr 25th, 2002, 12:07 PM   #4
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default

Hi,

I have the same questions as bergy, but I went forward and wrote something which may help.

I made the assumption that there is no issue with retrieving the data to a worksheet (i.e. your import already works and/or you have the file open and active).

Also, I am writing the data on the active sheet to "Sheet2" so please change to suit.

If there are any accounts which will cause more than 256 entries, this will bomb for sure.

Finally (!!!) if there are any blanks in the telephone number field, then your columns will not align consistently.

'-----------------
Sub test()
Dim counter As Long, lastrow As Long, x As Long
Dim matchrow As Long, lastcol As Integer

With ActiveSheet
.UsedRange
lastrow = .Cells.SpecialCells(xlCellTypeLastCell).Row
.Columns("G:G").Clear
.Columns("A:A").AdvancedFilter _
Action:=xlFilterCopy, CopyToRange:=Range("G1"), Unique:=True
.Range("G1").Delete shift:=xlUp

counter = WorksheetFunction.CountA(.Range("G:G"))
.Range("G1:G" & counter).Copy Sheets("sheet2").Range("A1")
.Range("G1:G" & counter).ClearContents

For x = 2 To lastrow
matchrow = Application.Match(.Cells(x, 1), Sheets("Sheet2").Range("A:A"), 0)
lastcol = Sheets("Sheet2").Cells(matchrow, 256).End(xlToLeft).Column
.Range(.Cells(x, 2), .Cells(x, 4)).Copy Sheets("Sheet2").Cells(matchrow, lastcol + 1)
Next x
End With
MsgBox "Done!"

End Sub
'---------------

HTH,
Jay
Jay Petrulis is offline   Reply With Quote
Old Apr 25th, 2002, 12:11 PM   #5
susanna
Board Regular
 
Join Date: Apr 2002
Posts: 58
Default

hi all -
thanks so much so far... I will try the code. but in answer to the questions, yes, it is absolutely ok to post the data on a new spreadsheet. Also, there will never be any more than 5 names associated with a particular account. In fact, there will ALWAYS be 5 names associated with a particular account.

Thanks again for all of your help!!!!

~s
susanna is offline   Reply With Quote
Old Apr 25th, 2002, 12:34 PM   #6
susanna
Board Regular
 
Join Date: Apr 2002
Posts: 58
Default

Jay -
I tried your code, and it worked great... only problem is (my fault!) I neglected to mention one of the columns... there is a column for the account #, name, ID, code and tel#... I ran your code and if i didn't delete one of the columns, it did it for me. Unfortunately, i know nothing yet about actually WRITING codes (i think i'm lucky enough to know where to put them once they're written!!!). Therefore, I do not know where to go into your code to make an amendment...
any help there?
thanks again!!!

~s
susanna is offline   Reply With Quote
Old Apr 25th, 2002, 12:46 PM   #7
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default

Hi Susanna,

I just answered a post that required the exact change you need.

Change
.Range(.Cells(x, 2), .Cells(x, 4)).Copy Sheets("Sheet2").Cells(matchrow, lastcol + 1)


to

.Range(.Cells(x, 2), .Cells(x, 5)).Copy Sheets("Sheet2").Cells(matchrow, lastcol + 1)

the difference is here:
Cells(x, 4)).Copy should be Cells(x, 5)).Copy
Jay Petrulis is offline   Reply With Quote
Old Apr 26th, 2002, 07:16 AM   #8
susanna
Board Regular
 
Join Date: Apr 2002
Posts: 58
Default

susanna is offline   Reply With Quote
Old Apr 26th, 2002, 07:18 AM   #9
susanna
Board Regular
 
Join Date: Apr 2002
Posts: 58
Default

oops... guess my previous post means i'm speechless! jay, thank you so very much for all of your help.. it worked like a charm.

susanna
susanna 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 05:57 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