If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > New to Macros

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-13-04, 09:57
exdter exdter is offline
Registered User
 
Join Date: Aug 2003
Posts: 328
New to Macros

I have never done a macro before. I have a table in Excel that looks like:

name1
company1
address1
name2
company2
address2
name3
company3
address3...

I would like it to look like this:

name1 company1
name2 company2
name3 company3...

Thanks.
Reply With Quote
  #2 (permalink)  
Old 08-13-04, 10:54
DavidCoutts DavidCoutts is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen, Scotland
Posts: 1,067
how about this

Code:
Sub test()
Dim I As Integer
Dim Lastrow As Integer

Lastrow = Range("A" & Rows.Count).End(xlUp).Row

    For I = 1 To Lastrow Step 3
        Range("A" & I & ":A" & I + 2).Copy
        Range("B" & I).PasteSpecial xlPasteAll, Transpose:=True
        Range("A" & I + 1 & ":A" & I + 2).Clear
    Next I
    
    Range("A1:A" & Lastrow).EntireRow.Sort Range("A1")
    Range("A1").EntireColumn.Delete
    
End Sub
Reply With Quote
  #3 (permalink)  
Old 08-13-04, 11:27
exdter exdter is offline
Registered User
 
Join Date: Aug 2003
Posts: 328
Thanks alot!!! That is amazing. The only problem is that my first column is sorted alphabetically and this throws off the whole table.

Thanks again.
Reply With Quote
  #4 (permalink)  
Old 08-13-04, 11:30
DavidCoutts DavidCoutts is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen, Scotland
Posts: 1,067
i sorted alphabetically at the end as this gets rid of the spaces, you could get rid of this and delete out all the blankrows if you like replace
Range("A1:A" & Lastrow).EntireRow.Sort Range("A1")

with
Range("A1:A" & Lastrow).specialcells(xlcelltypeblanks).entirerow. delete

dave
Reply With Quote
  #5 (permalink)  
Old 08-13-04, 11:55
exdter exdter is offline
Registered User
 
Join Date: Aug 2003
Posts: 328
Thank you VERY MUCH!!! That is exactly what I needed!!!
Thanks again!!!!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
Trackbacks are On
Pingbacks are On
Refbacks are On