troubleshooting Question

Newbie VBA Question

Avatar of Kenny537
Kenny537Flag for United States of America asked on
ProgrammingVisual Basic ClassicMicrosoft Excel
14 Comments4 Solutions677 ViewsLast Modified:
Hello,

I am very new to VBA and programming in general.  I am using this website right now to learn VBA.

http://excelexperts.com/Learn-VBA

I finished #1 and #2 successfully.  The website provides a good step-by-step outline of what to do.  But what it doesn't tell me is why to do that.  It provides no analysis of the code or anything.

Here is the code for #2:


Sub DisplayBiggest()
maxWeight = 0
For Each theCell In Range("D25:D34")
    If theCell.Value > maxWeight Then
        maxWeight = theCell.Value
        pigNumber = theCell.Offset(0, -1).Value
    End If
Next
MsgBox "The biggest piglet is number: " & pigNumber & " weighing:" & maxWeight
End Sub
-------------------------

I typed it in to the VBA editor, and sure enough - I did get a popup saying pig # 1 weights the most at 10.  But I do not understand how that code works.  Could someone please help me understand it, line to line?


Thanks!
ASKER CERTIFIED SOLUTION
DanMerk

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 4 Answers and 14 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 4 Answers and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros