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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:26:09+00:00 2026-05-27T10:26:09+00:00

I have an Excel Sheet with values going in each column from cells 2:21

  • 0

I have an Excel Sheet with values going in each column from cells 2:21

I need to highlight the corresponding cell in each column with the maximum value and try to loop through it with a macro. But I only know how to do it for a given hard-coded range..

Private Sub Worksheet_Activate()
Dim zelle As Range
  For Each zelle In ActiveSheet.Range("B2:B21")
    If zelle.Value = Application.WorksheetFunction.Max(Range("B2:B21")) Then
      zelle.Interior.ColorIndex = 6
    Else
      zelle.Interior.ColorIndex = xlNone
    End If
  Next
End Sub

I tried to use a new range for column which I gave the Range (“B:IT”) and iterate through that one but that didnt work.

Maybe it’s just 2 or 3 lines?

  • 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-05-27T10:26:09+00:00Added an answer on May 27, 2026 at 10:26 am

    This might work for you. Instead of using hard-coded ranges, it loops through whatever columns are used and adjusts for columns having different “lengths”. It assumes a single header row and column.

    Private Sub Worksheet_Activate()
    Dim zelle As Range
    Dim rng As Range
    Dim lCol As Long
    Dim lLastRow As Long
      With ActiveSheet
        For lCol = 2 To .UsedRange.Columns.Count
          lLastRow = .Cells(.Rows.Count, lCol).End(xlUp).Row
          Set rng = .Range(.Cells(2, lCol), .Cells(lLastRow, lCol))
          For Each zelle In rng
            If zelle.Value = Application.WorksheetFunction.Max(rng) Then
              zelle.Interior.ColorIndex = 6
            Else
              zelle.Interior.ColorIndex = xlNone
            End If
          Next
        Next lCol
      End With
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a cell in Excel sheet I have a Date value like: 01/01/2010 14:30:00
I have just Extracted the cells from the excel sheet using Apache POI, everything
Hai i have an excel sheet, in that i need to calculate some values
I have a excel sheet with cell value 0.010, 0.020 etc., I want to
I have a Excel sheet with two columns and I need to create new
I have an Excel sheet with two column, one is a number , and
I have a DataSet populated from Excel Sheet. I wanted to use SQLBulk Copy
I have a list of header values from an excel spreadsheet that is set
I have an excel sheet where I have duplicate values for many rows. How
i have this code in javascript a= Excel.Workbooks.open(C:/work/ind12.xls).ActiveSheet.Cells.find(value); if(a == null) document.getElementById('dateValid').innerText = Date

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.