Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 13th, 2008, 08:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default Macro in Excel

I want to write Macro in Excel

Excel sheet data like this

Sum_ID Text
----------------
111001 SC12-007
111001 SC12-008
111002 SC12-010
111003 SC14-006
111003 SC14-005
111004 SC02-009
111004 SC02-010
111004 SC02-007
111004 SC02-008
111004 SC02-005
111004 SC02-006
111005 SC12-019
111005 SC12-020
111005 SC12-018
111005 SC12-017
111006 SC12-012
111006 SC12-011
111007 SC12-013
111008 SC02-011
111008 SC02-012
111009 SC02-015
111009 SC02-013
111009 SC02-014
111010 SC12-026

I want to output of Macro should be like this

Sum_ID Text
--------------------------
111001 SC12-007, SC12-008
111002 SC12-010
111003 SC14-006, SC14-005
111004 SC02-009, SC02-010, SC02-007, SC02-008, SC02-005, SC02-006
111005 SC12-020, CS12-018, SC12-019, SC12-017
....
..

can anyone send me the macro code or help me to write above Macro.
Thanks and regards
Mateen


 
Old June 13th, 2008, 08:27 PM
Authorized User
 
Join Date: Nov 2007
Posts: 48
Thanks: 0
Thanked 4 Times in 4 Posts
Default

mateenmohd,

Here you go.

Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Press and hold down the 'ALT' key, and press the 'F11' key.
Insert a Module in your VBAProject, Microsoft Excel Objects.

Copy the below code, and paste it into the Module1.

Code:
Option Explicit
Sub Test()
    ' original code by jindon
    ' modified by stanleydgromjr
    '
    Dim a, i As Long, y, w(), myMax As Integer
    With ActiveSheet
        With .Range("a1").CurrentRegion.Resize(, 2)
            a = .Value
            .ClearContents
        End With
        With CreateObject("Scripting.Dictionary")
             For i = 1 To UBound(a, 1)
                  If Not .exists(a(i, 1)) Then
                       .Add a(i, 1), Array(a(i, 1), a(i, 2))
                  Else
                       w = .Item(a(i, 1))
                       ReDim Preserve w(UBound(w) + 1)
                       w(UBound(w)) = a(i, 2)
                       .Item(a(i, 1)) = w
                       myMax = WorksheetFunction.Max(myMax, UBound(w))
                  End If
             Next
             y = .items
        End With
        With .Range("a1")
            .Value = "Machine"
            .Offset(, 1).Resize(, myMax).Value = "Text"
            For i = 0 To UBound(y)
                .Offset(i).Resize(, UBound(y(i)) + 1).Value = y(i)
            Next
       End With
    End With
End Sub

Then run the "Test" macro.


Have a great day,
Stan

stanleydgromjr

Windows Vista Business and Excel 2003, 2007.
 
Old June 14th, 2008, 06:57 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks you very much.
Macro is very nice

can you post Excel Macro Learning good site address ?

Regards
Mateen


 
Old June 16th, 2008, 07:34 PM
Authorized User
 
Join Date: Nov 2007
Posts: 48
Thanks: 0
Thanked 4 Times in 4 Posts
Default

mateenmohd,

This site is good.

Also try:
http://www.mrexcel.com/
http://www.ozgrid.com/

You will have to create a free User Id and password for both sites - lots of good examples.


Have a great day,
Stan

stanleydgromjr

Windows Vista Business and Excel 2003, 2007.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Send It macro in excel hilding Excel VBA 2 September 6th, 2006 05:21 AM
exporting 2 excel by macro anukagni Access 2 January 30th, 2006 02:38 AM
Macro excel mathb79 Excel VBA 3 August 13th, 2005 06:55 PM
Excel 2000 vs Excel 2002 Macro Issue williadn Excel VBA 1 July 14th, 2005 09:09 AM
Excel 4.0 macro sezak99 Excel VBA 1 September 21st, 2003 11:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.