ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to select a range based on what's in the row header? (https://www.excelbanter.com/excel-programming/414142-how-select-range-based-whats-row-header.html)

Rachel Garrett

How to select a range based on what's in the row header?
 
I would like my macro to look for the word "Date" and then create a
range called "Date_Column", rather than hard-coding it that Date will
always be column B, column D, etc. Any suggestions or pointers to
tutorials?

Thanks,
Rachel

macgru

How to select a range based on what's in the row header?
 

Uzytkownik "Rachel Garrett" napisal w wiadomosci
...
I would like my macro to look for the word "Date" and then create a
range called "Date_Column", rather than hard-coding it that Date will
always be column B, column D, etc. Any suggestions or pointers to
tutorials?

Thanks,
Rachel


u can try with
Sub add_name()
Column = ActiveSheet.Rows(1).Find(What:="Date").Column
ActiveWorkbook.Names.Add Name:="Date_Column", RefersToR1C1:=Cells(1,
Column)' i assume it is row 1
End Sub

mcg



Gary''s Student

How to select a range based on what's in the row header?
 
Sub date_finder()
For Each r In ActiveSheet.UsedRange
If r.Value = "Date" Then
Set Date_Column = Columns(r.Column)
Exit For
End If
Next
End Sub

--
Gary''s Student - gsnu200795


"Rachel Garrett" wrote:

I would like my macro to look for the word "Date" and then create a
range called "Date_Column", rather than hard-coding it that Date will
always be column B, column D, etc. Any suggestions or pointers to
tutorials?

Thanks,
Rachel



All times are GMT +1. The time now is 03:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com