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 > Add up all numbers belonging to the same code name

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-10-11, 08:33
OB1 OB1 is offline
Registered User
 
Join Date: Dec 2007
Posts: 69
Add up all numbers belonging to the same code name

Hi,

I'm a complete newbie to VBA and I've written some code below to fill column 2 from B27 to B53 with the total figure of numbers relating to the code letter in column A27 to A53. The numbers are in another worksheet and there are loads of them that are duplicated in column 3 and the number to add would be in column 8! So the code letter on sheet (4) cell A27 is found on the other sheet(1) in column 3 and the number in column 8 is added to sheet(4) B27. This should then go down all of sheet(1) column 3 adding all that have the same code letter. Once it has done all for that code letter in goes to the next code letter in sheet(4) A28 and does it all again for that one. and so on....

Code:
Private Sub Get_Breakdown(ByVal Target As Range)
    
    
        Dim i As Integer
        Dim rnge As Range
        Dim rnge2 As Range
        
        Set rnge = Worksheets(1).Range("C:C")
        Set rnge2 = Worksheets(4)
        
        For i = 27 To 53
        
            For Each Cells In rnge
                If Cells.Value = rnge2.Cells(i, 1) Then
                    
                    rnge2.Cells(i, 2) = rnge2.Cells(i, 2) + Cells.Offset(0, 5).Value
                
                Else
                
            Next
            
        Next i
        
                    
End Sub
I was planning to run the code off of a button in the excel spreadsheet, but it just doesnt work and I'm not sure what I've done wrong? And as I said I'm a bit of a newbie, so any help will be greatly apriciated

Thank you,
Owain
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