PDA

View Full Version : help understanding code



aggiedb90
04-28-2011, 07:39 PM
hey everyone noob here...im a student learning VBA and im trying to understand a code that my teacher has posted. i can obviously run it and see what it does but im trying to understand step by step what the code is doing. here it is

Private Sub UserForm_Initialize()
Dim lastLetter As String
Dim ctrl As Control
Dim check As Boolean
check = True
For Each ctrl In Me.Controls
If TypeName(ctrl) = "TextBox" Then
lastLetter = Right(ctrl.Name, 1)
ctrl.Value = Range("D1").Offset(lastLetter, 0).Value
If Not IsNumeric(ctrl.Value) Then check = False
End If
Next ctrl
If check Then
lblData.Caption = "All Numeric Data"
Else
lblData.Caption = "Not All Numeric"
End If
End Sub

if someone could explain to me line by line what is happening that would be great. you dont have to explain the "end if" or the "next ctrl" ect..i understand y those are there. thanx again!

macropod
04-28-2011, 09:24 PM
Hi aggiedb90,

Most forum contributors, me included, disapprove helping people with their homework.

Bob Phillips
04-29-2011, 02:11 AM
A far more acceptable approach would be for you to tell us what you think it does, why it is written that way, and which bits you don't understand. We could then maybe give you hints, places/things to lookup.

Kenneth Hobs
04-29-2011, 06:02 AM
For the commands that you don't know, in the VBE, put your cursor near or in a word and press F1. You can then get specific help if it is a built-in command. Press F2 to open the command browser and type a command or word to get help there if like.

For objects with methods or properties, you can delete a period or a comma and retype it. Intellisense with then show available methods, properties and input parameters in a dropdownlist.