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

  • Home
  • SEARCH
  • 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 8895953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:55:03+00:00 2026-06-14T23:55:03+00:00

I need to write a macro that will find the cell range based on

  • 0

I need to write a macro that will find the cell range based on a value. A column will have the same value in a row, I need to find out what is the first and last column that has the same value in a row.enter image description here

So the macro needs to find that “Jill Cross” range is a4 to a9

So far I don’t have much, got a way to find the first occurrence of a value

   Function GetFirstCell(CellRef As Range)
   Dim l As Long
   l = Application.WorksheetFunction.Match(CellRef.Value, Range("A1:A10000"), 0)
   GetFirstCell = l
   End Function

Now I need to loop through the next rows somehow to return the last row of an occurrence

  • 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-14T23:55:04+00:00Added an answer on June 14, 2026 at 11:55 pm

    If you have your first cell in a sorted list, a countif function will give you the last cell easily.

       Function GetFirstCell(CellRef As Range) as long
           Dim l As Long
           l = Application.WorksheetFunction.Match(CellRef.Value, Range("A1:A10000"), 0)
           GetFirstCell = l
       End Function
    
       function GetLastCell(cellRef as range, lFirstCell as long)
           Dim l As Long
           l = Application.WorksheetFunction.countif(Range("A1:A10000"), CellRef.Value)
           GetLastCell = lFirstCell+l-1
       End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a macro in VBA that will open every file in
I need to write a macro that operates on bitarray looking like this: array[0]
I need to write a macro to clean up an Excel document. I have
I'm trying to write a macro that will generate a plain-text list of files
I'm a limited user, and I need to write an Outlook macro that exposes
I'm trying to write a macro that will copy the rows if 3 conditions
I need to write a multi-line macro. I need this because I must have
I learned that I need to write a macro if I want users to
I need to write a script in Matlab, which will read some data from
I need to write a C++ code coverage program that takes in another C++

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.