Macro to Sum %'s

xcelnovice

Board Regular
Joined
Dec 31, 2011
Messages
81
Hi,

I have a long list of %'s & I need to ensure each section individually adds up to 100%. Can a macro do this faster then me highlighting all of them? Below is a sample

18.94%
27.49%
10.81%
25.43%
0.87%
0.39%
7.47%
8.60%
50.74%
46.94%
1.60%
0.73%
63.67%
36.33%
50.74%
46.94%
1.60%
0.73%

<COLGROUP><COL style="WIDTH: 48pt" width=64><TBODY>
</TBODY>
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Code:
Sub checkPercents()

    Dim sumchecks As Variant
    Dim rowStart As Long


    rowStart = 1


    For x = 1 To Cells(Rows.Count, "A").End(xlUp).Row + 1
        Select Case Cells(x, 1)
            Case ""
                If sumchecks <> 1 Then
                    Range(Cells(rowStart, 1), Cells(x - 1, 1)).Interior.Color = vbYellow
                End If
                sumchecks = 0
                rowStart = x + 1
            Case Else
                sumchecks = sumchecks + Cells(x, 1)
        End Select
                
    Next x


End Sub

This will highlight offending sections yellow. It does highlight 100.01% so you've been warned. I don't know if you want it that exact. It also assumes your data is in column A.
 
Upvote 0

Forum statistics

Threads
1,216,816
Messages
6,132,859
Members
449,761
Latest member
AUSSW

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