teethebuilder18
New Member
- Joined
- Jul 18, 2018
- Messages
- 4
Hi All,
I am not sure that this is the correct place to post this, but I have a VBA question.
I found a set of code online to do what I desire, but I need to modify it to suit my needs. What I am doing is this:
I have a set of Names and values separated in my excel sheet as "Divisions" ex:
Division 290-01
Board - 1
Board - 2
Board - 3
Stud - 4
Stud - 5
Stud - 6
In the example above, the item (board; stud) and the number next to it (1-6) are in separate cells next to each other. I found a section of code online that allows me to consolidate repeating names and sum the values like such:
Division 290-01
Board - 6
Stud - 15
The problem I'm having is that I have Multiple divisions, and have to run the code over again for each division.
Example:
Division 290-01
Board - 1
Board - 2
Board - 3
Stud - 4
Stud - 5
Stud - 6
Division 300-01
Board - 1
Board - 2
Board - 3
Stud - 4
Stud - 5
Stud - 6
My goal is to create a section of code that works through the whole sheet to consolidate the items by Division like this:
Division 290-01
Board - 6
Stud - 15
Division 300-01
Board - 6
Stud - 15
The code I am using right now has to be run for each division, and as you could imagine this is very time consuming. Thanks in advance for your help. Please see below, this is the code I am using to run each division individually:
Sub CombineRows()
'Update 20130829
Dim WorkRng As Range
Dim Dic As Variant
Dim arr As Variant
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Set Dic = CreateObject("Scripting.Dictionary")
arr = WorkRng.Value
For i = 1 To UBound(arr, 1)
Dic(arr(i, 1)) = Dic(arr(i, 1)) + arr(i, 2)
Next
Application.ScreenUpdating = False
WorkRng.ClearContents
WorkRng.Range("A1").Resize(Dic.Count, 1) = Application.WorksheetFunction.Transpose(Dic.keys)
WorkRng.Range("B1").Resize(Dic.Count, 1) = Application.WorksheetFunction.Transpose(Dic.items)
Application.ScreenUpdating = True
End Sub
I am not sure that this is the correct place to post this, but I have a VBA question.
I found a set of code online to do what I desire, but I need to modify it to suit my needs. What I am doing is this:
I have a set of Names and values separated in my excel sheet as "Divisions" ex:
Division 290-01
Board - 1
Board - 2
Board - 3
Stud - 4
Stud - 5
Stud - 6
In the example above, the item (board; stud) and the number next to it (1-6) are in separate cells next to each other. I found a section of code online that allows me to consolidate repeating names and sum the values like such:
Division 290-01
Board - 6
Stud - 15
The problem I'm having is that I have Multiple divisions, and have to run the code over again for each division.
Example:
Division 290-01
Board - 1
Board - 2
Board - 3
Stud - 4
Stud - 5
Stud - 6
Division 300-01
Board - 1
Board - 2
Board - 3
Stud - 4
Stud - 5
Stud - 6
My goal is to create a section of code that works through the whole sheet to consolidate the items by Division like this:
Division 290-01
Board - 6
Stud - 15
Division 300-01
Board - 6
Stud - 15
The code I am using right now has to be run for each division, and as you could imagine this is very time consuming. Thanks in advance for your help. Please see below, this is the code I am using to run each division individually:
Sub CombineRows()
'Update 20130829
Dim WorkRng As Range
Dim Dic As Variant
Dim arr As Variant
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Set Dic = CreateObject("Scripting.Dictionary")
arr = WorkRng.Value
For i = 1 To UBound(arr, 1)
Dic(arr(i, 1)) = Dic(arr(i, 1)) + arr(i, 2)
Next
Application.ScreenUpdating = False
WorkRng.ClearContents
WorkRng.Range("A1").Resize(Dic.Count, 1) = Application.WorksheetFunction.Transpose(Dic.keys)
WorkRng.Range("B1").Resize(Dic.Count, 1) = Application.WorksheetFunction.Transpose(Dic.items)
Application.ScreenUpdating = True
End Sub