Sum Columns based on part of the information in the first column

awiltz

New Member
Joined
Jun 6, 2020
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hello,
I am working on data where each row has a 9 digit number assigned to it (College Campuses). The first 6 digits are specific to each College and the last 3 are labels for each Location. I then have columns and columns of data for each. What I would like to do is have the columns summed based on the first 6 numbers of the 9 digit number (combine the data for all locations into 1 line). I also then want the last 3 numbers to be deleted so that there is only the first 6 numbers remaining and everything from the columns that started with those 6 numbers added together into 1 final sum. I have been doing this manually but with 14,000+ rows, it is going to take me months to process this all manually.
Thank you for any help you can give,
awiltz
 
I'm not sure what process you are talking about?

Forget the word "process".
You have these data:
Libro1
ABCDEFGHIJKLMNOPQRSTUVW
1UNITID_PINSTNMINSTNM14INSTNM11INSTNM08sector_cdSector_descmen_totalwomen_totalTotalMURD17MURD16MURD15MURD14MURD13MURD12MURD11MURD10MURD9MURD8NEG_M17NEG_M16NEG_M15
2105792001South Mountain Community CollegeSouth Mountain Community CollegeSouth Mountain Community CollegeSouth Mountain Community College4Public, 2-year1714240641200000000000000
3105792002South Mountain Community CollegeSouth Mountain Community CollegeSouth Mountain Community CollegeSouth Mountain Community College4Public, 2-year171424064120000000000000
4105792003South Mountain Community College0
Hoja1


What I would like to do is have the columns summed based on the first 6 numbers of the 9 digit number (combine the data for all locations into 1 line)
You want to show how you put it on a line.

I also then want the last 3 numbers to be deleted so that there is only the first 6 numbers remaining and everything from the columns that started with those 6 numbers added together into 1 final sum.
You want a sum, but your example only has zeros, so what do you want to sum?
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
The sum is what I want. The portion of data I put up is murder rates which are typically 0 or 1. Here is a set of data for just 1 college with the last row showing how I manually combine the rows above into 1 row. What I would typically do after this is delete all the rows but the last one.

All Crime Data.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZBABBBCBDBEBFBGBHBIBJBKBLBMBNBOBPBQBRBSBTBUBVBWBXBYBZCACBCCCDCECFCGCHCICJCKCLCMCNCOCPCQCRCSCTCUCVCWCXCYCZDADBDCDDDEDFDGDHDIDJDKDLDMDNDODPDQDRDSDTDUDVDWDXDYDZEAEBECEDEEEFEGEHEIEJEKELEMENEOEPEQERESETEUEVEWEXEYEZFAFBFCFDFEFFFGFHFIFJFKFLFMFNFOFPFQFRFSFTFUFVFWFX
250109785001Azusa Pacific UniversityAzusa Pacific UniversityAzusa Pacific UniversityAzusa Pacific University2Private nonprofit, 4-year or above309768299926000000000000000000000374106400000010484610000000000001120011000005429433816114117616483632766364200000000000101001001161010230102502121000010352820111911507700000200311221221585956161527280312211502532
251109785002Azusa Pacific UniversityAzusa Pacific UniversityAzusa Pacific UniversityAzusa Pacific University2Private nonprofit, 4-year or above30976829992600000000000000000000000000000000000000000000000000000000000000000001000020002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100
252109785004Azusa Pacific UniversityAzusa Pacific UniversityAzusa Pacific UniversityAzusa Pacific University2Private nonprofit, 4-year or above30976829992600000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000002000000000000000000000000100000000000000000000000
253109785005Azusa Pacific UniversityAzusa Pacific UniversityAzusa Pacific UniversityAzusa Pacific University2Private nonprofit, 4-year or above30976829992600000000000000000000000000000000000000000000000000000000000000120000001010110000003000000000000000000000000000000000000100000000000000000000000000000000000000000000000000
254109785006Azusa Pacific UniversityAzusa Pacific UniversityAzusa Pacific UniversityAzusa Pacific University2Private nonprofit, 4-year or above30976829992600000000000000000000000000000000000000000000000000000000001000000000000010000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000
255109785007Azusa Pacific UniversityAzusa Pacific UniversityAzusa Pacific UniversityAzusa Pacific University2Private nonprofit, 4-year or above30976829992600000000000000000000000000000000000000000000000000101000000000000000000001000100002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
256109785008Azusa Pacific UniversityAzusa Pacific UniversityAzusa Pacific UniversityAzusa Pacific University2Private nonprofit, 4-year or above30976829992600000000000000000000000000000000000000000000000000000000000000000000010000000000001000000000000000000000000000000000000000000010000000000000000000100000000000000000000010
257109785009Azusa Pacific UniversityAzusa Pacific UniversityAzusa Pacific University00000000000000000000000000000000000000000000102000000000000000000000000000000000000000000000000000000000000000
258109785Azusa Pacific University0000000000000000000003741064000000104846100000000001021200120001254294438181243217184957327612464200000000000101001001161010230102503141000020352820111911507700000200511221221585956161527280312211502642
All Crime Data
 
Upvote 0
Sorry, but I still don't understand.
You have this:
varios 07jun2020.xlsm
ABFGHIJKL
1UNITID_PINSTNMsector_cdSector_descmen_totalwomen_totalTotal
2109785001Azusa Pacific University2Private nonprofit, 4-year or above30976829992663
3109785002Azusa Pacific University2Private nonprofit, 4-year or above30976829992600
4109785004Azusa Pacific University2Private nonprofit, 4-year or above30976829992600
5109785005Azusa Pacific University2Private nonprofit, 4-year or above30976829992630
6109785006Azusa Pacific University2Private nonprofit, 4-year or above30976829992601
7109785007Azusa Pacific University2Private nonprofit, 4-year or above30976829992620
8109785008Azusa Pacific University2Private nonprofit, 4-year or above30976829992610
910978500900
Sheet1


And you want this:
varios 07jun2020.xlsm
ABCDEFGHIJKL
1UNITID_PINSTNMINSTNM14INSTNM11INSTNM08sector_cdSector_descmen_totalwomen_totalTotal
2109785Azusa Pacific University124
Sheet2


Obviously for all rows and for all columns.
 
Upvote 0
That's correct. Take all entries for 1 university and condense it down into 1 line just like you have it.
 
Upvote 0
Try this.
Your data on sheet1, the results on sheet2. Replace "Sheet1" and "Sheet2" in the macro with the names of your sheets.

VBA Code:
Sub Sum_Columns()
  Dim i As Long, j As Long, k  As Long, lc As Long
  Dim a As Variant, b As Variant, dic As Object
  
  With Sheets("Sheet1")
    lc = .Cells.Find("*", , xlValues, , xlByColumns, xlPrevious).Column
    a = .Range("A2", .Cells(.Range("A" & Rows.Count).End(3).Row, lc)).Value2
    ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
  End With
  Set dic = CreateObject("Scripting.Dictionary")
  
  For i = 1 To UBound(a, 1)
    If Not dic.exists(Left(a(i, 1), 6)) Then
      j = j + 1
      dic(Left(a(i, 1), 6)) = j
      b(j, 1) = Left(a(i, 1), 6)
      For k = 2 To 10
        b(j, k) = a(i, k)
      Next
    End If
    j = dic(Left(a(i, 1), 6))
    For k = 11 To UBound(a, 2)
      b(j, k) = b(j, k) + a(i, k)
    Next
  Next
  With Sheets("Sheet2")
    .Rows("2:" & Rows.Count).ClearContents
    .Range("A2").Resize(j, UBound(b, 2)).Value = b
  End With
End Sub
 
Upvote 0
Thank you for putting this together. I ran it on the data and it appears to have worked exactly how I wanted. I'm going to do some spot checking to make sure but if it all works out you saved me hundreds of hours. I cannot thank you enough. Please let me know if I can compensate you for your work.
 
Upvote 0
You already did it, thanking the work is enough. Let me know if you have any questions.
 
Upvote 0

Forum statistics

Threads
1,214,636
Messages
6,120,664
Members
448,976
Latest member
sweeberry

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top