+ Reply to Thread
Results 1 to 7 of 7

Need help with a loop

  1. #1
    Registered User
    Join Date
    12-01-2020
    Location
    United States
    MS-Off Ver
    version 2002 (build 12527.21330)
    Posts
    2

    Question Need help with a loop

    Fisrt off I would like to say I'm new to VBA and I don't have a lot of knowledge about it so any help would be appreciated. So I'm having trouble with a loop. When I run the code it outputs the results as 0 into the exam rows so I don't know whats wrong with the loop. The scores must be divided by 40

    Student Score Exam%
    Albrecht 27.5
    Alsindi 7.0
    Bailey 34.0
    Bedert 24.5
    Bertsch 27.5
    Bills 29.5
    Bluester 31.5
    Brunstotlar 26.0
    Cannon 37.5
    Cunningham 33.0
    El-Baba 27.0
    Erwin 32.5
    Ethier 35.5
    Ewersen 34.0
    Frazier 29.0
    Gigax 30.0
    Haberstro 38.5
    Judge 33.5
    Knauf 38.5
    Kreger 37.0
    Langenderfer 32.0
    Lettman 31.5
    Li 17.0
    Lyons 39.5
    Maniak 34.5
    Monticure 31.5
    Montoya 39.0
    Murray 15.0
    Patil 21.0
    Phipps 32.0
    Price 26.0
    Sherman 35.5
    Small 35.5
    Song 27.5
    Sun 27.0
    Wagner 33.5


    This is my code so far

    Sub grade()

    Dim introw As Double
    Dim row As Double
    Dim intlastrow As Double
    Dim intScore As Integer
    Dim intGrade As Integer
    Dim intAvg As Integer
    Dim intHigh As Integer
    Dim intPass As Integer
    Dim intFail As Integer

    Const intbasis As Integer = 40

    intlastrow = Cells(Rows.Count, "A").End(xlUp).row
    introw = 2

    intScore = Range("B" & introw)
    intGrade = Range("C" & introw)

    Do While (Range("A" & introw) <> "")
    intGrade = intScore / intbasis
    introw = introw + 1
    Exit Do
    Loop


    End Sub
    Last edited by Marshall18; 12-01-2020 at 08:03 PM.

  2. #2
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,425

    Re: Need help with a loop

    Actually, your code is not outputting anything. Also it is not entirely clear from your description nor your code what it is you are trying to do. Why don't you give us a more detailed description of what you are trying to do. It would also help immensely if you included a sample workbook that shows your existing data and also shows what the final output should be for that sample data (see the yellow banner at the top of the forum's webpage to see how to properly attach a file to your message).

  3. #3
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Need help with a loop

    See if this will give you the results you are looking for.

    Please Login or Register  to view this content.
    the problem with your code is that this
    Please Login or Register  to view this content.
    does not create a valid range reference it would need to be like
    Please Login or Register  to view this content.
    Just looked at the added graphic in the OP and it looks a lot like homework. If it is, then you are cheating by using this forum.
    Last edited by JLGWhiz; 12-02-2020 at 10:16 AM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  4. #4
    Registered User
    Join Date
    12-01-2020
    Location
    United States
    MS-Off Ver
    version 2002 (build 12527.21330)
    Posts
    2

    Re: Need help with a loop

    Thanks for the quick reply. I updated the post with a screenschot and sample workbook!

  5. #5
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,425

    Re: Need help with a loop

    I don't see a screen shot or a sample workbook. Did you follow the instructions in the yellow banner at the top of this forum's webpage?

  6. #6
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Need help with a loop

    Quote Originally Posted by Rick Rothstein View Post
    I don't see a screen shot or a sample workbook. Did you follow the instructions in the yellow banner at the top of this forum's webpage?
    There was a screen shot there, but it has been removed. The screen shot basically duplicated what the OP had typed in previously. Apparently all they wanted was to divide each test score by 40 and put the result in column C.

  7. #7
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,425

    Re: Need help with a loop

    Quote Originally Posted by JLGWhiz View Post
    Apparently all they wanted was to divide each test score by 40 and put the result in column C.
    Had I understood that, I probably would have posted this non-looping macro (it works and would have thwarted its use if the OP's post was a homework assignment)...
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Loop through emails to find Email today, if not found loop Date -1
    By lougs7 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-29-2020, 12:48 PM
  2. [SOLVED] VBA to loop through cell-defined range and paste table output after each loop.
    By mscott123 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-18-2019, 03:41 AM
  3. [SOLVED] (Beginner help) For loop inside do loop that displays information from reference sheet.
    By lediable007 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-08-2016, 03:20 PM
  4. [SOLVED] Auto email loop with formatted table data breaking on second loop VBA
    By Who_else in forum Excel General
    Replies: 6
    Last Post: 03-24-2016, 06:22 AM
  5. [SOLVED] VBA to loop within a loop of multiple blocks of data (currentregion) ... Expert needed
    By Jim885 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-20-2016, 08:28 PM
  6. [SOLVED] Copy dynamically changing column and Paste using VBA Loop (Loop within Loop)
    By nixon72 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2013, 12:46 PM
  7. Why did an inner loop variable start overwriting the outer loop range suddenly?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-16-2012, 03:24 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1