Help with Dynamic Array

Elogger

New Member
Joined
Oct 22, 2015
Messages
23
[TABLE="width: 512"]
<tbody>[TR]
[TD="colspan: 8"]Can someone please help me with this? I'm really struggling. Write a macro reports the sum of squares of negative #'s, sum of squares of the positive #'s, the maximum and the minimum numbers in a messagebox. You do not know the size of the table but can assume the user will choose the first cell (upper left cell) of the table and run your macro. [/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Code:
Sub DoHomeworkProblem()

    Dim rngCell As Range
    Dim rng As Range
    Dim lMax As Long
    Dim lMin As Long
    Dim lPosSQ As Long
    Dim lNegSQ As Long

    Set rng = Selection.CurrentRegion
    
    For Each rngCell In rng
        Select Case rngCell.Value
        Case Is > 0
            lPosSQ = lPosSQ + rngCell.Value ^ 2
        Case Else
            lNegSQ = lNegSQ + rngCell.Value ^ 2
        End Select
        If rngCell.Value > lMax Then lMax = rngCell.Value
        If rngCell.Value < lMin Then lMin = rngCell.Value
    Next
    
    MsgBox "Number of Cells: " & rng.Cells.Count & vbLf & _
        "Sum of Positive #s Squared: " & lPosSQ & vbLf & _
        "Sum of Negative #s Squared: " & lNegSQ & vbLf & _
        "Max Value: " & lMax & vbLf & _
        "Min Value: " & lMin, , "Homework Answers"
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,226,695
Messages
6,192,475
Members
453,726
Latest member
JoeH57

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