Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old December 15th, 2005, 02:28 AM
Registered User
Join Date: Dec 2005
Location: Kolkata, West Bengal, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to vicky.dalmia Send a message via Yahoo to vicky.dalmia
Default Need Help For A Macro Code

Hello EveryBody

This is Vikash Here and ,this is my first time I am Posting my Problem, Kindly Look into it and help me out


I am writing a macro for an Excel Sheet. The Excel Sheet Look Like This:

Ord No Trd Qty Ord Qty

200512135273 800 3100
200512135273 600 2300
200512135273 700 1700
200512135273 1000 1000
200512135275 500 700
200512135275 200 200
200512136450 100 300
200512136450 200 200

Want I want is According to order No i.e. 200512135273 which is having 4 Nos. of trade of diff. qty to sum it up and get a single row which showing as

Ord No Trd Qty Ord Qty

200512135273 3100 3100
200512135275 700 700
200512136450 300 300

Plz help me to solve the prob

Vikash Dalmia
Reply With Quote
  #2 (permalink)  
Old December 16th, 2005, 07:37 AM
Authorized User
Join Date: Oct 2004
Location: , , .
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to shattered Send a message via Yahoo to shattered

Ok, first up, I wouldn't usually do this with code, I'd either use Excels built in subtotals or a pivot table - you might want to consider that..

Anyway, that aside, here is some code that will do what you need :

Sub Collate_Data(sSheet As String, i1 As Integer, i2 As Integer)
    ' Check how many different elements there are
    Dim dNum() As Double
    ReDim dNum(i1 To i2)
    dNum(i1) = Sheets(sSheet).Cells(i1, 2).Value
    iInc = i1
    For iLoop = i1 To i2
        bMatch = False
        For iLoop2 = i1 To i2
            If dNum(iLoop2) = Sheets(sSheet).Cells(iLoop, 2).Value Then bMatch = True
        If bMatch = False Then
            iInc = iInc + 1
            dNum(iInc) = Sheets(sSheet).Cells(iLoop, 2).Value
        End If
    ReDim Preserve dNum(i1 To iInc)
    ' Create New table entries
    For iLoop = LBound(dNum) To UBound(dNum)
        Sheets(sSheet).Cells(iLoop, 8).Value = dNum(iLoop)
        For iLoop1 = i1 To i2
            If Sheets(sSheet).Cells(iLoop1, 2).Value = dNum(iLoop) Then
                Sheets(sSheet).Cells(iLoop, 9).Value = Sheets(sSheet).Cells(iLoop, 9).Value + Sheets(sSheet).Cells(iLoop1, 3).Value
                Sheets(sSheet).Cells(iLoop, 10).Value = Sheets(sSheet).Cells(iLoop, 10).Value + Sheets(sSheet).Cells(iLoop1, 4).Value
            End If
        Next iLoop1
End Sub

This code assumes that you are passing it the sheet name, first row that the data is in and the last row that the data is in
The column number has been assumed as 2 for the Ord No.
The result data is written to the right in columns 8 9 and 10

Additional parameters can easily be added if you want this to change often..

Reply With Quote

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
calling to xlam macro from macro inside xlsb SteveB Excel VBA 0 June 30th, 2008 07:43 PM
Run code in Macro Corey Access VBA 4 February 5th, 2007 10:54 AM
How to protect macro code? kotaiah Excel VBA 1 September 25th, 2006 03:57 PM
Hide VBA code when forwarding macro sh333384 Excel VBA 7 September 2nd, 2004 11:23 AM
Macro or Code? lryckman Access 7 August 24th, 2004 02:00 AM

All times are GMT -4. The time now is 03:25 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.