Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8921275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:29:58+00:00 2026-06-15T06:29:58+00:00

I know the code probably isn’t very good but I’m still learning VBA. I’ve

  • 0

I know the code probably isn’t very good but I’m still learning VBA.

I’ve created a worksheet that organizes my college course list but I’m trying to make it so that the code executes automatically when I change a value in the first two columns.

An “x” in the first column selects that as a completed course which subtracts the credit hours for that class from the total hours required. An “S” and some number in the second column denotes a semester and sums up the credit hours to be taken per semester, for example, if I enter “S1” next to “Study and Careers in Engineering”, then it will take that 1 credit hour for that class and add it to the total amount of hours for the entire semester.

The two codes are completely independent of each other.

Screenshot of worksheet:
https://i.stack.imgur.com/pTsiy.png

Code:

Private Sub Calculations()

    Dim creditsLeft As Integer creditsLeft = 130

    For i = 3 To 43
        If Cells(i, 1).Value = "x" Then creditsLeft = (creditsLeft - Cells(i, 8)) Next i

    Range("J3").Value = creditsLeft


    Dim S1creds, S2creds, S3creds, S4creds, S5creds, S6creds As Integer

    For i = 3 To 43
        If Cells(i, 2).Value = "S1" Then S1creds = (S1creds + Cells(i, 8))
        If Cells(i, 2).Value = "S2" Then S2creds = (S2creds + Cells(i, 8))
        If Cells(i, 2).Value = "S3" Then S3creds = (S3creds + Cells(i, 8))
        If Cells(i, 2).Value = "S4" Then S4creds = (S4creds + Cells(i, 8))
        If Cells(i, 2).Value = "S5" Then S5creds = (S5creds + Cells(i, 8))
        If Cells(i, 2).Value = "S6" Then S6creds = (S6creds + Cells(i, 8)) 
    Next i

    Range("J9").Value = "Sem 1 Hrs: " 
    Range("J10").Value = "Sem 2 Hrs: "
    Range("J11").Value = "Sem 3 Hrs: " 
    Range("J12").Value = "Sem 4 Hrs: "
    Range("J13").Value = "Sem 5 Hrs: " 
    Range("J14").Value = "Sem 6 Hrs: "

    Range("K9").Value = S1creds 
    Range("K10").Value = S2creds
    Range("K11").Value = S3creds 
    Range("K12").Value = S4creds
    Range("K13").Value = S5creds 
    Range("K14").Value = S6creds

    End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:29:59+00:00Added an answer on June 15, 2026 at 6:29 am

    You don’t even need VBA for that.

    I3: =130-SUMIF(A3:A43,"x",H3:H43)
    K9: =SUMIF(B3:B43,"S1",H3:H43)
    K10: =SUMIF(B3:B43,"S2",H3:H43)
    K11: =SUMIF(B3:B43,"S3",H3:H43)
    K12: =SUMIF(B3:B43,"S4",H3:H43)
    K13: =SUMIF(B3:B43,"S5",H3:H43)
    K14: =SUMIF(B3:B43,"S6",H3:H43)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From the question you can probably tell that I don't know much about code!
I know inline code is preferable, but there's a bunch of code that's needed
I realize that this is probably a very basic question, but I have spent
I know the code is missing (Someone will give negative numbers). But I only
In code: //I know that to get this effect (being able to use it
I know that c++ code should be compiled and linked by g++, not gcc.
Alright, probably not the best title, but meh. I have the following code inside
You know that particular part of your code that is essential for the project
I was coding an usual jquery+AJAX code, but it isn't working and i really
I have read probably all posts and documentation but I still can't solve this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.