Consulting

Results 1 to 4 of 4

Thread: help understanding code

  1. #1

    help understanding code

    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

    [VBA]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[/VBA]

    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!
    Last edited by Bob Phillips; 04-29-2011 at 02:10 AM. Reason: Added VBA tags

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Hi aggiedb90,

    Most forum contributors, me included, disapprove helping people with their homework.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •