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 9225781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:39:56+00:00 2026-06-18T04:39:56+00:00

i want to shorten this code and i know it’s possible i just dont

  • 0

i want to shorten this code and i know it’s possible i just dont know the proper syntax

i want to create a subroutine to update the font colors and just call it from the if statements by changing just the first cell letter

would someone mind helping so i can keep this in mind for future reference

thanks in advance,

EDIT: just to clarify, i want to do something like this

    If Not Intersect(Target, Range("C3")) Is Nothing Then 'do the following if e3 is updated

'reset all font colors to black
Range("C8:K9,C14:K14,C37:K37").Font.ColorIndex = 1
Range("C7:K7,C11:K11,C13:K13,C23:K23,C28:K28").Font.ColorIndex = 1
Range("C10:K10,C15:K16").Font.ColorIndex = 1
Range("C17:K17").Font.ColorIndex = 1
Range("C18:K18,C33:K33").Font.ColorIndex = 1
Range("C24:K26,C29:K31").Font.ColorIndex = 1
Range("C32:K32").Font.ColorIndex = 1
Range("C36:K36,C38:K38").Font.ColorIndex = 1

    If Range("C3") = "1" Then ' do the following if C3 is 1
         updateFontColor c
    ElseIf Range("C3") = "2" Then ' do the following if C3 is 2
        updateFontColor d
    ElseIf Range("C3") = "3" Then ' do the following if C3 is 3
          updateFontColor e 
    ElseIf Range("C3") = "4" Then ' do the following if C3 is 4
        updateFontColor f

    ElseIf Range("C3") = "5" Then ' do the following if C3 is 5
        updateFontColor g

    ElseIf Range("C3") = "6" Then ' do the following if C3 is 6
              updateFontColor h     
    ElseIf Range("C3") = "7" Then ' do the following if C3 is 7
            updateFontColor i       
    ElseIf Range("C3") = "8" Then ' do the following if C3 is 8
            updateFontColor j       
    ElseIf Range("C3") = "9" Then ' do the following if C3 is 9
           updateFontColor k
               End If
End If

Sub updateFontColor(x As Range)
        Range("x8:K9,x14:x14,x37:K37").Font.ColorIndex = 2
        Range("x7:K7,x11:K11,x13:K13,x23:K23,x28:K28").Font.ColorIndex = 39
        Range("x10:K10,x15:K16").Font.ColorIndex = 35
        Range("x17:K17").Font.ColorIndex = 28
        Range("x18:K18,x33:K33").Font.ColorIndex = 38
        Range("x24:K26,x29:K31").Font.ColorIndex = 36
        Range("x32:K32").Font.ColorIndex = 44
        Range("x36:K36,x38:K38").Font.ColorIndex = 15
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-18T04:39:57+00:00Added an answer on June 18, 2026 at 4:39 am

    String concatenation operator: &

    Pass the variable x as string:

    Call your sub by passing a string:

    updateFontColor("K")
    

    The sub:

    Sub updateFontColor(x As String) 'pass x as string, not range
        Range(x & "8:K9," & x & "14:K14," & x & "37:K37").Font.ColorIndex = 2
        .
        .
        .
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this css code, and i want to shorten it. #one{ background: #6cab26;
How can i shorten this code? I want to return all values except abc
First, I don't know if this is actually possible but what I want to
I have this code in a function, and want to shorten it - it
To create and show a form takes 10 seconds and i want to shorten
I'm just starting out with JQuery. My Question: I want to know if I
I found this code below and it works perfect for what I want BUT
I have this several lines of code. It's function is that it will create
I wanted to know if there was a way to shorten this if statement
want to know why String behaves like value type while using ==. String s1

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.