+ Reply to Thread
Results 1 to 4 of 4

Thread: Using Nested loops in VBA macro for excel

  1. #1
    Registered User
    Join Date
    12-06-2011
    Location
    ny
    MS-Off Ver
    Excel 2010
    Posts
    2

    Using Nested loops in VBA macro for excel

    Hi,

    I need to create a macro in excel and I am really struggling to create the nested loop necessary. I attached a file of a short pdf, it is very basic programming for Visual Basic in excel but I am very new to it and am having lots of trouble.

    If someone took a few minutes out of their time and looked at it I would be extremely grateful.
    Attached Files Attached Files
    Last edited by sfoy; 12-06-2011 at 11:43 PM.

  2. #2
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,276

    Re: Using Nested loops in VBA macro for excel

    Thanks for changing the title. Do you have some code that you can provide us to help you with? You will have a hard time getting someone to do your assignment from this forum but we will help with code that you are struggling with.
    Please leave a message after the beep!

  3. #3
    Registered User
    Join Date
    12-06-2011
    Location
    ny
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Using Nested loops in VBA macro for excel

    Yes i have some code that i have done so far. Really all i can figure out is how to find the rows that are unique (meaning the unique buyer id numbers). SO all i can figure out is how to transfer the information to the first column of the second table. I am completely lost on how to loop my code so that when i find the unique buyer id numbers, to then add the sums of the # of shares together to display in the next column.

    [Sub ReArrange()

    Dim i As Integer 'Loop counter 1
    Dim k As Integer ' Loop Counter 2
    Dim intuniquecount As Integer 'accumulator to count number of unique records
    Dim blnUnique As Boolean 'a flag to note whether record is unique
    Dim intsharescounter As Integer

    Worksheets(2).Cells.Delete
    intsharescounter = 0
    For i = 1 To 39
    blnUnique = True
    For k = 1 To i - 1
    If Sheets(1).Cells(i, 4) = Sheets(1).Cells(k, 4) Then
    blnUnique = False
    Exit For
    End If
    Next k
    If blnUnique = True Then
    intuniquecount = intuniquecount + 1

    Sheets(1).Cells(i, 4).Copy Destination:=Sheets(2).Cells(intuniquecount, 1)

    End If
    Next i
    For







    Worksheets(2).Select
    Range("A1").FormulaR1C1 = "Trader ID"
    Range("B1").FormulaR1C1 = "Buy Shares"
    Range("C1").FormulaR1C1 = "Buy Amount"
    Range("A1:C1").Select
    Selection.Font.Bold = True
    Range("A1:C1").Select

    With Selection.Borders(xlEdgeBottom)
    .LineStyle = xlDouble
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlThick
    End With
    Columns("C:C").NumberFormat = "$#,##0"
    Columns("A:A").Select
    With Selection
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlBottom
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
    End With
    Sheets(2).Columns.AutoFit
    Cells(1, 1).Select]




    End Sub
    Last edited by sfoy; 12-07-2011 at 01:21 PM.

  4. #4
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,276

    Re: Using Nested loops in VBA macro for excel

    Hi sfoy, I strongly encourage you to read the forum rules (you can find the link in my signature. You need to wrap your code in code tags as per Rule #3. It makes for easier reading of code and keeps the threads here clutter free (looking).
    Please leave a message after the beep!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0