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!
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!