Consulting

Results 1 to 3 of 3

Thread: I need help with this VBA exam example

  1. #1
    VBAX Newbie
    Joined
    Jan 2016
    Posts
    1
    Location

    I need help with this VBA exam example

    I don't even know where to start...part1.jpgpart2.jpg

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    See the help file for these KeyWords: For, Loop, End, Columns, Rows, Set, Min, Max, Date, DateDiff, and WorksheetFunction.

    MS has an Excel 2010 Developer Documentation.chm help file for download, or you can search the internet for "VBA" + the KeyWord.

    Although you don't really need End, Rows, and Columns for the first example, it is Best Practice to avoid the use of Magic Numbers.

    With Excel, DateTime values are displayed as Dates and Times, depending on the Cell Format, but are stored as Doubles.



    Experiment: Enter two dates in Ranges A1 and B1. Format C1 as a Number. Enter "= A1-B1" in C1.

    Format C1 as a number with 11 decimal places, In A1, type "=NOW()".

    Put this code in the Worksheet's code page and run it
    Sub Test
    Cells(2, 1) = Cells(1, 2)
    End Sub


    Final hint: Never use a KeyWord, (a Reserved word,) as a variable name.
    Use: Rng vice Range
    Cel vice Cell
    Rw vice Row
    Col vice Column
    Sht vice sheet
    WkBk vice WorkBook
    Etc
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Most forums have rules about not helping with homework. http://www.vbaexpress.com/forum/faq....q_hom_faq_item
    If you want help with homework, make the attempt to solve it first. There is nothing wrong asking for help with concepts though. That is part of problem solving, understanding what concepts are involved.

    You are in a programming class and don't know how to even get started? Obviously, your first step is to put the data into a file in the cells shown. Make sure that your dates are the numeric value and not the Formatted string value. Press Ctrl+1 to set formats. Same concept applies to strings with dollar or comma characters, those are formats and seldom should be entered as strings. Most teachers would prefer that your learn concepts and not just solve and not know why.

    In VBE, put your cursor in a command word or next to it and press F1 to get specific help. Used F2 to browse for help in general.
    Command words here might be:
    Max or WorksheetFunction.Max
    Min or WorksheetFunction.Min
    If
    Then
    Else
    Do
    While
    Single
    String
    Range
    Set
    For
    ForEach
    Array
    Offset
    Function

    Search the web or this forum for UDF.

    These words can be in a Sub or a Function in the Code window or the Immediate Window in the VBE.

    If you view forum threads and try to solve them and then view the solution(s), you learn more. The best way to learn, is to teach. So, replay to a thread even if you can only solve part of it. You will be notified of replies so you can view the solutions and say wow, I never thought to solve it that way, I am saving it for my toolbox.

    Keep in mind that professors scan the web for cheating. In the end, it is you that gets cheated when cheating.

Tags for this Thread

Posting Permissions

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