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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:06:36+00:00 2026-05-28T16:06:36+00:00

Here is a sample spreadsheet I want to select a range (ex: A2:E2 )

  • 0

Here is a sample spreadsheet

Sample table

I want to select a range (ex: A2:E2) and get the value 1. If I select A4:E4 I will get the value 1; and so on. Is there any way to achieve this with a macro?

Another thing I would need is the value in the first row of the corresponding column. Ex:

If I select A2:E2 I want to get n (since 1 is in column E), if I select A4:E4 I want to get v (since 1 is in column C).

  • 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-28T16:06:37+00:00Added an answer on May 28, 2026 at 4:06 pm

    Ok, here is a function which you can use as a formula in the workbook. It also addresses both your questions. 🙂

    Paste the below code in a module.

    SYNTAX/USAGE

    =MyFunc(Cell Range, Arg)

    Cell Range: (Required) A range such as A2:E2

    Arg: (Required) Can take a value of “H” Or “R”. “H” will give you the column Header and “R” will give you the row value

    Example

    =MyFunc(A1:E2,”H”) will give you “n” AND

    =MyFunc(A1:E2,”R”) will give you “1”

    Option Explicit
    
    Function MyFunc(rng As Range, stype As String) As Variant
        Dim MyArray() As String
        Dim sCol As Long
    
        If stype = "" Or (UCase(stype) <> "H" And _
        UCase(stype) <> "R") Then Exit Function
    
        With rng
            MyArray = Split(.Address, "$")
    
            sCol = Cells(Val(MyArray(UBound(MyArray))), _
            Columns.Count).End(xlToLeft).Column
    
            If UCase(stype) = "H" Then
                MyFunc = Cells(1, sCol)
            ElseIf UCase(stype) = "R" Then
                MyFunc = Range(MyArray(UBound(MyArray) - 1) & _
                MyArray(UBound(MyArray))).Value
            End If
        End With
    End Function
    

    Note: This is just a general code to show you how it works and it doesn’t handle any errors at the moment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is sample query SELECT name, sum(SELECT id FROM mytable WHERE cond='1' and cond2='2')
I have this function (sample here: http://jsbin.com/emabe4/ ) var a=[]; var log = document.getElementById('log');
I´m littel confused with this reserve key and cases caused errors. Here a sample
I am trying to reuse Apple's Speak Here sample code in my own iPhone
Here is my sample code: from xml.dom.minidom import * def make_xml(): doc = Document()
Here is a sample from Kernighan & Ritchie's The C Programming Language: int getline(char
Here is a sample code to retrieve data from a database using the yield
Here is the sample: Dim TestString As String = Hello, & Chr(0) & World
Here is my sample code. It is meant to be an iterative procedure for
here is some sample javascript: SomeObjectType = function() { } SomeObjectType.prototype = { field1:

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.