Closed Thread
Results 1 to 13 of 13

Help Needed: Excel VBA For Creative Problem Solving Part 1 Assignment 4

  1. #1
    Registered User
    Join Date
    05-01-2023
    Location
    Singapore
    MS-Off Ver
    (Version 2302 Build 16.0.16130.20378) 64-bit
    Posts
    66

    Help Needed: Excel VBA For Creative Problem Solving Part 1 Assignment 4

    Assignment 4 - STARTER.xlsm

    Problem Statement:

    INSTRUCTIONS: In the "Assignment 4 - STARTER.xlsm" file, you will find information for a bunch of batches from a certain process. Column A contains the Batch ID, Column B contains the production date, and Column C contains the ship date.

    The Batch ID has a two-digit code to the left of the hyphen and a 3- or 4-digit code to the right of the hyphen. The first letter of the Batch ID is known as the Identifier and the leading number of the 3- or 4-digit code to the right of the hyphen is known as the Key. For example, in the Batch ID "N9-363B", the Identifier is "N" and the Key is 3.

    Your goal is to create a subroutine that allows the user to select the Identifier from a drop-down menu in cell F2 and the Key from a drop-down menu in cell F3 (these drop-down/data validation menus are already available in the starter file) and any rows of the data (columns A, B, and C) whose Batch ID meets those criteria will be highlighted GREEN.

    The RUN button is linked to the HighlightRows subroutine in the starter file. The RESET button is already linked to the Reset subroutine in the starter file so please do not modify it. When run, the RESET button (or Reset sub) will remove any fill color/highlighting from anywhere on the "Data" sheet. However, it will not remove any additional rows that you may add, so be sure to reset the data (by copying/pasting) present in the "Original Data" tab if you add or change any of the original data.

    IMPORTANT: Also contained within the starter file are 3 additional procedures: 1) a sub called Example, 2) a function called Identifier, and 3) a function called Key. The Identifier function takes as an argument a Batch ID and outputs the Identifier. The Key function takes as an argument a Batch ID and outputs the Key. I encourage you to utilize these functions within your HighlightRows sub - you can see how to use these two functions in the Example sub.

    Requirements:

    1) When a match is found in a row, all three columns of data (columns A, B, and C) must be highlighted green.

    2) "Green" refers to the interior color index equal to 4. For example, Range("A1").Interior.ColorIndex = 4 would color cell A1 green. The grader file is specifically looking for this ColorIndex! If you color the cells a different shade of green, it won't pass the grader!

    3) When additional rows are added to the data (for example, in row 27 and beyond), your sub should automatically detect the size of data (number of rows) and adjust accordingly.

    Hints

    I would recommend using the Range approach to working with data arrays such as this. See the screencast "Iterating through a Selection vs. a Range" and pay close attention to the approach using Range instead of Selection.

    Note that in the starter file, cell F2 has been named "identifier" and cell F3 has been named "key".


    Could someone help me out with the problem above and screenshot your code in your VBEditor?
    Last edited by webcam723; 05-01-2023 at 11:35 AM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: Excel VBA For Creative Problem Solving Part 1 Assignment 4

    Did you have an excel question?

  3. #3
    Registered User
    Join Date
    05-01-2023
    Location
    Singapore
    MS-Off Ver
    (Version 2302 Build 16.0.16130.20378) 64-bit
    Posts
    66

    Re: Excel VBA For Creative Problem Solving Part 1 Assignment 4

    Can you help me out with the assignment above and screenshot your code in the VBEditor? I am totally stuck and unsure how to begin.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,457

    Re: Excel VBA For Creative Problem Solving Part 1 Assignment 4

    What have you tried?

    Nothing is more frustrating than to be working on homework and to get stuck. Without guidance, you might have no hope of finishing the assignment before the deadline. The Internet can be a big help in that respect, but without learning how to get the right answer, asking others to solve your homework questions for you simply becomes a downward spiral (and it's cheating).

    We do not want to contribute to you cheating yourself out of your education, but we also acknowledge that seeking assistance to learn a concept is a legitimate request.

    If you are genuinely interested in receiving help in the form of tutoring or coaching, then please rephrase the title of your original post to clearly indicate you are seeking coaching or tutoring help. Any forum members (who are willing to assist as a tutor) will modify their responses accordingly to facilitate your learning. Tutors don't tell you the answers, they help you figure it out for yourself; so don't expect answers, expect suggestions, or just plain hints. Also, be specific in describing the function/formula or technique you trying to learn, and tell us what you have attempted so far. Otherwise, expect your plea for homework answers to be ignored.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Registered User
    Join Date
    05-01-2023
    Location
    Singapore
    MS-Off Ver
    (Version 2302 Build 16.0.16130.20378) 64-bit
    Posts
    66

    Re: Help Needed: Excel VBA For Creative Problem Solving Part 1 Assignment 4

    Attachment 827689

    This is what I've got so far. There is still something missing in the code.

  6. #6
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: Help Needed: Excel VBA For Creative Problem Solving Part 1 Assignment 4

    You missed nesting your if statement
    Please Login or Register  to view this content.
    Probably start your loop at row 2
    Please Login or Register  to view this content.
    The you don't have to add 1 to the color row
    Please Login or Register  to view this content.
    I edited the Key function, you are looking for the 4th character.
    Please Login or Register  to view this content.
    Last edited by davesexcel; 05-02-2023 at 09:23 AM.

  7. #7
    Registered User
    Join Date
    05-01-2023
    Location
    Singapore
    MS-Off Ver
    (Version 2302 Build 16.0.16130.20378) 64-bit
    Posts
    66

    Re: Help Needed: Excel VBA For Creative Problem Solving Part 1 Assignment 4

    Attachment 827763

    Sub HighlightRows()
    'Place your code here
    Dim nr As Integer, I As Integer, ID As String, key As Integer
    nr = WorksheetFunction.CountA(Columns("A:A"))
    For I = 2 To nr
    ID = Range("A2:A" & nr)
    If Identifier(ID) = Range("identifier") And key(ID) = Range("key") Then
    Range("A" & I & ":" & "C" & I).Interior.ColorIndex = 4
    End If
    Next I
    End Sub

    Is this correct?
    Last edited by webcam723; 05-02-2023 at 07:21 AM.

  8. #8
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: Help Needed: Excel VBA For Creative Problem Solving Part 1 Assignment 4

    Did it work?

  9. #9
    Registered User
    Join Date
    05-01-2023
    Location
    Singapore
    MS-Off Ver
    (Version 2302 Build 16.0.16130.20378) 64-bit
    Posts
    66

    Re: Help Needed: Excel VBA For Creative Problem Solving Part 1 Assignment 4

    Hi Dave! Sorry but it did not work. I keep getting "compile error expected array".

  10. #10
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: Help Needed: Excel VBA For Creative Problem Solving Part 1 Assignment 4

    You need to tell it what ID is.
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    08-21-2023
    Location
    Singapore
    MS-Off Ver
    Microsoft 365
    Posts
    1

    Post Re: Help Needed: Excel VBA For Creative Problem Solving Part 1 Assignment 4

    Thank you
    Last edited by LPT4N; 08-24-2023 at 10:36 PM.

  12. #12
    Registered User
    Join Date
    10-04-2023
    Location
    Norfolk, VA
    MS-Off Ver
    Office 365
    Posts
    3

    Re: Help Needed: Excel VBA For Creative Problem Solving Part 1 Assignment 4

    Hi all,
    Can someone to provide me with a to solve the assignment #4? My subroutine as follows:

    Sub HighlightRows()
    Dim nr As Integer, i As Integer, identifier As String, key As Integer
    nr = WorksheetFunction.CountA(Columns("A:A")) - 1
    For i = 1 To nr
    If identifier(Range("A" & i + 1)) = Range("identifier") And key(Range("A" & i + 1)) =
    Range("key") Then Range("A:C" & i).Interior.ColorIndex = 4
    End If

    Next i

    End Sub


    Not sure why "expected array" error pops up.

    Please, I just want an "advice" , not a complete fix.

    Thanks in advance
    PS: fairly new with VBA by the way

  13. #13
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,890

    Re: Help Needed: Excel VBA For Creative Problem Solving Part 1 Assignment 4

    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #1 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Kindly Help in Solving this Excel Problem
    By yousufsaleem in forum Excel General
    Replies: 1
    Last Post: 12-07-2015, 06:37 PM
  2. Multivariate Calculus in Excel - Help Solving a Problem
    By el4n in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 08-07-2012, 04:52 PM
  3. Need help in solving a problem using Excel 2007
    By newbieexcel123 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-05-2010, 12:59 PM
  4. Mathematic problem solving using Excel
    By Stonewall in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-15-2006, 03:20 PM
  5. Replies: 1
    Last Post: 02-04-2006, 06:10 PM
  6. [SOLVED] i've got a simple excel problem that needs solving...
    By Massive in forum Excel General
    Replies: 8
    Last Post: 05-16-2005, 04:28 AM
  7. [SOLVED] Thorny VBA problem. Any creative solution appreciated.
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-21-2005, 06:06 AM

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