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, 12:17 PM   #1
jbyrne
Board Regular
 
Join Date: Feb 2002
Posts: 165
Default


IN SOME CASES I HAVE THE SAME NAME WITH MULTIPLE ADDRESSES. FOR EXAMPLE

COLUMN A B C D E
JOHN SMITH 123 MAIN ST ANYTOWN NJ 07622
JOHN SMITH 421 SOUTH DR ANYTOWN NJ 07624
JOHN SMITH 923 9TH AVE ANYTOWN NJ 07221
MARY DOE 123 5TH ST ANYTOWN OH 23473
MARY DOE 523 2ND ST ANYTOWN PA 34737

WHAT I WANT TO DO IS HAVE THE ADDRESSES GOING ACCROSS INSTEAD OF DOWNWARD IN THE COLUMN. EXAMPLE ABOVE (IF SAME NAME MOVE B2 TO F1)

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

Hi,

http://www.mrexcel.com/board/viewtop...6317&forum=2&4

does something similar.

I would recommend that you concatenate the first and last names in another column and then try the above procedure (adapt it, of course).

HTH,
Jay
Jay Petrulis is offline   Reply With Quote
Old Apr 25th, 2002, 12:28 PM   #3
jbyrne
Board Regular
 
Join Date: Feb 2002
Posts: 165
Default

Thanks Jay,

I'm learning more and more about excel every day. I'm not to sure where I paste the code and how do I start it.

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

Hi,

I misread your post a bit. I was under the impression that the names were in separate columns. I think they are complete and in column A. You do *not* need to manipulate the original data in any way then.

Below the instructions are the modified code. Let me know if this works for you.

1. Make sure your data is on the active sheet.

2. Make sure the active sheet is not Sheet2

3. Copy the code below

4. Go back to Excel and hold down the Alt key while depressing the F11 key on the top row. (Alt-F11). You will now be in the Visual Basic Editor (VBE)

5. From the top menu Insert>Module

6. Paste the code you copied.

7. Type Alt-Q to exit the VBE and return to Excel proper.

8. Run the program, by doing either:

a) Tools>Macro>Macros choose test and hit OK
b) Alt+F8 and choose test, OK.

'---begin VBA---
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, 5)).Copy Sheets("Sheet2").Cells(matchrow, lastcol + 1)
Next x
End With
MsgBox "Done!"

End Sub
'---end VBA---

Please post back if you have any troubles.

Bye,
Jay
Jay Petrulis is offline   Reply With Quote
Old Apr 25th, 2002, 12:54 PM   #5
jbyrne
Board Regular
 
Join Date: Feb 2002
Posts: 165
Default

Thanks Jay,

I'll let you know how I do!

Jim
jbyrne is offline   Reply With Quote
Old Apr 26th, 2002, 09:12 AM   #6
jbyrne
Board Regular
 
Join Date: Feb 2002
Posts: 165
Default

Hi Jay,

It worked GREAT! Now I just need to adjust it a little bit...

On sheet 2, I just need the additional addresses and the dates of the individuals. (Columns B thru H)

Also Jay, is it possible to include the 1st record as well on sheet 2?

I appreciate all the help you are giving me!!
jbyrne is offline   Reply With Quote
Old Apr 26th, 2002, 09:16 AM   #7
jbyrne
Board Regular
 
Join Date: Feb 2002
Posts: 165
Default

Sorry Jay, I responded to the wrong thread. I will now respond to this thread only... my last response was due to your response about inserting the following sub

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("N:N").Clear
.Columns("A:A").AdvancedFilter _
Action:=xlFilterCopy, CopyToRange:=Range("N1"), Unique:=True
.Range("N1").Delete shift:=xlUp

counter = WorksheetFunction.CountA(.Range("N:N"))
.Range("N1:N" & counter).Copy Sheets("sheet2").Range("A1")
.Range("N1:N" & 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, 13)).Copy Sheets("Sheet2").Cells(matchrow, lastcol + 1)
Next x
End With
MsgBox "Done!"

End Sub
jbyrne is offline   Reply With Quote
Old Apr 26th, 2002, 10:47 AM   #8
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default

Response sent through private e-mail. Did not realize you had sent to group as well.

To only transfer Col's B through H, change
.Range(.Cells(x, 2), .Cells(x, 13)).Copy
to
.Range(.Cells(x, 2), .Cells(x, 8)).Copy

To include first record (I assumed you had category headers), change
For x = 2 To lastrow
to
For x = 1 To lastrow

Bye,
Jay

[ This Message was edited by: Jay Petrulis on 2002-04-26 12:27 ]
Jay Petrulis is offline   Reply With Quote
Old Apr 26th, 2002, 01:17 PM   #9
fb250r
Board Regular
 
Join Date: Apr 2002
Posts: 104
Default

Hello Jay,

I have a similar problem that I posted under "Combine data". I tried your posted suggestion but it's not quite there.

Any Suggestions?

Regards,

Frank
fb250r is offline   Reply With Quote
Old Apr 26th, 2002, 01:26 PM   #10
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default

Hi Frank,

This is becoming a popular routine. If your original data does *not* have a category header, then change

For x = 2 To lastrow
to
For x = 1 To lastrow

Here is the sub rewritten if only columns A and B hold data that needs to be transferred.

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("N:N").Clear
.Columns("A:A").AdvancedFilter _
Action:=xlFilterCopy, CopyToRange:=Range("N1"), Unique:=True
.Range("N1").Delete shift:=xlUp

counter = WorksheetFunction.CountA(.Range("N:N"))
.Range("N1:N" & counter).Copy Sheets("sheet2").Range("A1")
.Range("N1:N" & 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
.Cells(x, 2).Copy Sheets("Sheet2").Cells(matchrow, lastcol + 1)
Next x
End With
MsgBox "Done!"

End Sub

Bye,
Jay
Jay Petrulis 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 03:24 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