Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Finding the right column

I have a row, that looks like this:

| Fender bb | Fender ee | Fender ff | Line 1 |

Now, the number of fender columns could vary, so my question is, how do
I get the column number/letter of the column that contains "Line" as
the first four letters (because it is not always line 1)?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Finding the right column

Hi JaMark,

Try something like:

'=============
Public Sub Tester()
Dim rng As Range
Dim col As Long

With ActiveSheet
On Error Resume Next
Set rng = .Cells.Find(What:="Line*", _
After:=.Range("A1"), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)
End With
On Error GoTo 0

If Not rng Is Nothing Then MsgBox rng.Column

End Sub
'<<=============


--
---
Regards,
Norman



"JaMark" wrote in message
oups.com...
I have a row, that looks like this:

| Fender bb | Fender ee | Fender ff | Line 1 |

Now, the number of fender columns could vary, so my question is, how do
I get the column number/letter of the column that contains "Line" as
the first four letters (because it is not always line 1)?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Finding the right column

Thanks Norman, that's just what I need :o)


Norman Jones wrote:
Hi JaMark,

Try something like:

'=============
Public Sub Tester()
Dim rng As Range
Dim col As Long

With ActiveSheet
On Error Resume Next
Set rng = .Cells.Find(What:="Line*", _
After:=.Range("A1"), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)
End With
On Error GoTo 0

If Not rng Is Nothing Then MsgBox rng.Column

End Sub
'<<=============


--
---
Regards,
Norman



"JaMark" wrote in message
oups.com...
I have a row, that looks like this:

| Fender bb | Fender ee | Fender ff | Line 1 |

Now, the number of fender columns could vary, so my question is, how do
I get the column number/letter of the column that contains "Line" as
the first four letters (because it is not always line 1)?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Finding the right column

If need to refer to that column, do I write like this?

..Range(ColLet(Tester())&"3") 'I have a function (ColTest()) that
converts the number into a letter

Norman Jones wrote:
Hi JaMark,

Try something like:

'=============
Public Sub Tester()
Dim rng As Range
Dim col As Long

With ActiveSheet
On Error Resume Next
Set rng = .Cells.Find(What:="Line*", _
After:=.Range("A1"), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)
End With
On Error GoTo 0

If Not rng Is Nothing Then MsgBox rng.Column

End Sub
'<<=============


--
---
Regards,
Norman



"JaMark" wrote in message
oups.com...
I have a row, that looks like this:

| Fender bb | Fender ee | Fender ff | Line 1 |

Now, the number of fender columns could vary, so my question is, how do
I get the column number/letter of the column that contains "Line" as
the first four letters (because it is not always line 1)?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Finding the right column

Hi JaMark,

There is no need to convert the column number to a letter.

Try something like:

Cells(3, ColNumber)

---
Regards,
Norman



"JaMark" wrote in message
oups.com...
If need to refer to that column, do I write like this?

.Range(ColLet(Tester())&"3") 'I have a function (ColTest()) that
converts the number into a letter

Norman Jones wrote:
Hi JaMark,

Try something like:

'=============
Public Sub Tester()
Dim rng As Range
Dim col As Long

With ActiveSheet
On Error Resume Next
Set rng = .Cells.Find(What:="Line*", _
After:=.Range("A1"), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)
End With
On Error GoTo 0

If Not rng Is Nothing Then MsgBox rng.Column

End Sub
'<<=============


--
---
Regards,
Norman



"JaMark" wrote in message
oups.com...
I have a row, that looks like this:

| Fender bb | Fender ee | Fender ff | Line 1 |

Now, the number of fender columns could vary, so my question is, how do
I get the column number/letter of the column that contains "Line" as
the first four letters (because it is not always line 1)?






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Finding the right column

Ok, thanks. That was really helpful, but still, how do I refer to the
function? Like this?

..Range(Tester()&"3")

Norman Jones wrote:
Hi JaMark,

There is no need to convert the column number to a letter.

Try something like:

Cells(3, ColNumber)

---
Regards,
Norman



"JaMark" wrote in message
oups.com...
If need to refer to that column, do I write like this?

.Range(ColLet(Tester())&"3") 'I have a function (ColTest()) that
converts the number into a letter

Norman Jones wrote:
Hi JaMark,

Try something like:

'=============
Public Sub Tester()
Dim rng As Range
Dim col As Long

With ActiveSheet
On Error Resume Next
Set rng = .Cells.Find(What:="Line*", _
After:=.Range("A1"), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)
End With
On Error GoTo 0

If Not rng Is Nothing Then MsgBox rng.Column

End Sub
'<<=============


--
---
Regards,
Norman



"JaMark" wrote in message
oups.com...
I have a row, that looks like this:

| Fender bb | Fender ee | Fender ff | Line 1 |

Now, the number of fender columns could vary, so my question is, how do
I get the column number/letter of the column that contains "Line" as
the first four letters (because it is not always line 1)?



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Finding the right column

Hi JaMark,

Ok, thanks. That was really helpful, but still, how do I refer to the
function? Like this?

.Range(Tester()&"3")


If I understand you correctly, try something like:

Sub Macro1()
Dim rng As Range
Dim col As Long

With ActiveSheet
On Error Resume Next
col = .Cells.Find(What:="Line*", _
After:=.Range("A1"), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False).Column
End With
On Error GoTo 0

If col = 1 Then
Set rng = Cells(3, col)
End If

MsgBox rng.Address(0, 0)
End Sub




--
---
Regards,
Norman



"JaMark" wrote in message
oups.com...
Ok, thanks. That was really helpful, but still, how do I refer to the
function? Like this?

.Range(Tester()&"3")



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
finding the largest value for a name in a column and then returningthe result from a different column [email protected] Excel Worksheet Functions 1 April 14th 08 10:08 AM
Finding the closest number in column A and take the value in column B reefguy Excel Worksheet Functions 3 May 5th 06 07:25 PM
Finding all matches in column B with datalist in column A Pops Jackson Excel Programming 3 April 11th 06 08:10 PM
Output from a userform finding the right column. column HelpMe Excel Programming 1 February 10th 04 03:27 PM
finding and reporting in column A, where a series of column reaches zero Gary Tamblyn Excel Programming 2 July 27th 03 12:00 PM


All times are GMT +1. The time now is 05:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"