+ Reply to Thread
Results 1 to 2 of 2

VBA Excel part 1 Assignment 1

  1. #1
    Registered User
    Join Date
    12-13-2023
    Location
    london
    MS-Off Ver
    2019
    Posts
    1

    Post VBA Excel part 1 Assignment 1

    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.

    So far I could do till here only, please help

    Sub HighlightRows()
    Dim nr As Integer, i As Integer, Identifier() As String, Key() As String, ID As String, Z As String, Y As String
    Reset
    nr = WorksheetFunction.CountA(Columns("A:A"))
    For i = 1 To nr
    ID = Range("A" & i + 1)
    Y = Key(ID)
    Z = Identifier(ID)
    If Z = Range("identifier") & Y = Range("key") Then Range("A:A").Interior.ColorIndex = 4
    Next i
    End Sub

    Sub Example()
    ' This is just to show how the Identifier and Key functions below can be utilized in VBA code
    Dim ID As String, i As Integer, nr As Integer
    nr = WorksheetFunction.CountA(Columns("A:A"))
    ID = Range("A" & i + 2)
    MsgBox "The identifier is " & Identifier(ID) & " and the key is " & Key(ID)
    End Sub

    Function Identifier(ID As String) As String
    Identifier = Left(ID, 1)
    End Function

    Function Key(ID As String) As Integer
    Key = Left(Mid(ID, 4, 4), 1)
    End Function

    Sub Reset()
    ' Obtained through a macro recording:
    With Cells.Interior
    .Pattern = xlNone
    .TintAndShade = 0
    .PatternTintAndShade = 0
    End With
    End Sub

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2507 (Windows 11 Home 24H2 64-bit)
    Posts
    91,792

    Re: VBA Excel part 1 Assignment 1

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however we recommend that you include code tags around your code.

    Please take a moment to add the tags. Posting code between [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Guideline #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

+ 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. Excel VBA For Creative Problem Solving Part 1 Assignment 4
    By chiky1972 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-14-2025, 10:35 AM
  2. Help Needed: Excel VBA For Creative Problem Solving Part 1 Assignment 4
    By webcam723 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-04-2023, 08:28 PM
  3. Need help with Excel assignment
    By Srikanth9581 in forum Excel General
    Replies: 1
    Last Post: 09-06-2023, 01:56 AM
  4. Replies: 1
    Last Post: 09-14-2021, 11:19 AM
  5. Wildcard search by text part and its assignment
    By excelhilfe in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-10-2021, 06:41 AM
  6. EXCEL Macro Buttons lose assignment, switches to another macro assignment periodically
    By girl4betterworld in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-29-2020, 08:08 PM
  7. assignment excel.....
    By pat207 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-30-2010, 09:45 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