Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Offset based on column heading

Excel Experts,

I would like to select a range offset to the right from the original range
based on the column headings.

My spreadsheet is similar to the following


A B C D
1 Acct Entry
2
3 4J6N 15
4 4J6N 15
5 4J6N 15
6 4J6N 15
7

Set St4J6N = Cells.Find(What:="4J6N").Select

Range("A100").Select

Set End4J6N = Cells.Find(What:="4J6N", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious)

Set rng4J6N = Range(St4J6N, End4J6N)

Set EntryS = Cells.Find(What:="Entry")

trd4J6N.Offset(, D1EntryS.Columns.Count - trd4J6N(1).Columns.Count).Select

End Sub

The final line isn't working. My goal is to select cells C3..C6.

What code will do this?

Thanks in advance.

Alan

--
achidsey
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Offset based on column heading

One way:

Option Explicit
Sub testme02()

Dim FoundCell1 As Range
Dim FoundCell2 As Range
Dim rng As Range
Dim WhatToFind As String

WhatToFind = "4J6N"

With Worksheets("sheet1")

With .Range("a:a")
If Application.CountIf(.Cells, WhatToFind) < 2 Then
MsgBox "not enough to find!"
Exit Sub
End If

Set FoundCell1 = .Cells.Find(What:=WhatToFind, _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

Set FoundCell2 = .Cells.Find(What:=WhatToFind, _
After:=.Cells(1), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False)

End With

Set rng = .Range(FoundCell1, FoundCell2).Offset(0, 2)

Application.Goto rng

End With

End Sub

achidsey wrote:

Excel Experts,

I would like to select a range offset to the right from the original range
based on the column headings.

My spreadsheet is similar to the following

A B C D
1 Acct Entry
2
3 4J6N 15
4 4J6N 15
5 4J6N 15
6 4J6N 15
7

Set St4J6N = Cells.Find(What:="4J6N").Select

Range("A100").Select

Set End4J6N = Cells.Find(What:="4J6N", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious)

Set rng4J6N = Range(St4J6N, End4J6N)

Set EntryS = Cells.Find(What:="Entry")

trd4J6N.Offset(, D1EntryS.Columns.Count - trd4J6N(1).Columns.Count).Select

End Sub

The final line isn't working. My goal is to select cells C3..C6.

What code will do this?

Thanks in advance.

Alan

--
achidsey


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Offset based on column heading

Oops. I didn't notice that the columns could vary position:

Option Explicit
Sub testme02()

Dim FoundCell1 As Range
Dim FoundCell2 As Range
Dim FoundCell3 As Range
Dim FoundCell4 As Range

Dim rng As Range

Dim WhatToFind1 As String
Dim WhatToFind2 As String
Dim WhatToFind3 As String

WhatToFind1 = "Acct"
WhatToFind2 = "Entry"
WhatToFind3 = "4J6N"

With Worksheets("sheet1")

With .Rows(1)
Set FoundCell1 = .Cells.Find(What:=WhatToFind1, _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

Set FoundCell2 = .Cells.Find(What:=WhatToFind2, _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End With

If FoundCell1 Is Nothing _
Or FoundCell2 Is Nothing Then
MsgBox "Headers not found in row 1!"
Exit Sub
End If

With FoundCell1.EntireColumn

Set FoundCell3 = .Cells.Find(What:=WhatToFind3, _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

Set FoundCell4 = .Cells.Find(What:=WhatToFind3, _
After:=.Cells(1), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False)

If FoundCell1 Is Nothing Then
MsgBox WhatToFind3 & " not found in the correct column"
Exit Sub
End If
End With

Set rng = .Range(FoundCell3, FoundCell4)

Set rng = rng.Offset(0, FoundCell2.Column - FoundCell1.Column)

Application.Goto rng

End With

End Sub

<<snipped

achidsey wrote:

Excel Experts,

I would like to select a range offset to the right from the original range
based on the column headings.

My spreadsheet is similar to the following

A B C D
1 Acct Entry
2
3 4J6N 15
4 4J6N 15
5 4J6N 15
6 4J6N 15
7

Set St4J6N = Cells.Find(What:="4J6N").Select

Range("A100").Select

Set End4J6N = Cells.Find(What:="4J6N", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious)

Set rng4J6N = Range(St4J6N, End4J6N)

Set EntryS = Cells.Find(What:="Entry")

trd4J6N.Offset(, D1EntryS.Columns.Count - trd4J6N(1).Columns.Count).Select

End Sub

The final line isn't working. My goal is to select cells C3..C6.

What code will do this?

Thanks in advance.

Alan

--
achidsey


--

Dave Peterson


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Offset based on column heading

And a typo (sigh):

Option Explicit
Sub testme02()

Dim FoundCell1 As Range
Dim FoundCell2 As Range
Dim FoundCell3 As Range
Dim FoundCell4 As Range

Dim rng As Range

Dim WhatToFind1 As String
Dim WhatToFind2 As String
Dim WhatToFind3 As String

WhatToFind1 = "Acct"
WhatToFind2 = "Entry"
WhatToFind3 = "4J6N"

With Worksheets("sheet1")

With .Rows(1)
Set FoundCell1 = .Cells.Find(What:=WhatToFind1, _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

Set FoundCell2 = .Cells.Find(What:=WhatToFind2, _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End With

If FoundCell1 Is Nothing _
Or FoundCell2 Is Nothing Then
MsgBox "Headers not found in row 1!"
Exit Sub
End If

With FoundCell1.EntireColumn

Set FoundCell3 = .Cells.Find(What:=WhatToFind3, _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

Set FoundCell4 = .Cells.Find(What:=WhatToFind3, _
After:=.Cells(1), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False)

If FoundCell3 Is Nothing Then
MsgBox WhatToFind3 & " not found in the correct column"
Exit Sub
End If
End With

Set rng = .Range(FoundCell3, FoundCell4)

Set rng = rng.Offset(0, FoundCell2.Column - FoundCell1.Column)

Application.Goto rng

End With

End Sub
<<snipped
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 139
Default Offset based on column heading

achidsey:

try,

Dim MyRange As Range
Dim c As Range
With Worksheets(1).Columns(1)
Set c = .Find("4J6N", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
If MyRange Is Nothing Then
Set MyRange = c
Else
Set MyRange = Union(MyRange, c)
End If
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
MyRange.Offset(, 2).Select
End With

--
天行健,君*以自強不息
地勢坤,君*以厚德載物

http://www.vba.com.tw/plog/


"achidsey" wrote:

Excel Experts,

I would like to select a range offset to the right from the original range
based on the column headings.

My spreadsheet is similar to the following


A B C D
1 Acct Entry
2
3 4J6N 15
4 4J6N 15
5 4J6N 15
6 4J6N 15
7

Set St4J6N = Cells.Find(What:="4J6N").Select

Range("A100").Select

Set End4J6N = Cells.Find(What:="4J6N", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious)

Set rng4J6N = Range(St4J6N, End4J6N)

Set EntryS = Cells.Find(What:="Entry")

trd4J6N.Offset(, D1EntryS.Columns.Count - trd4J6N(1).Columns.Count).Select

End Sub

The final line isn't working. My goal is to select cells C3..C6.

What code will do this?

Thanks in advance.

Alan

--
achidsey



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Offset based on column heading


Dave and chijanzen,

Thanks for the assistance.

Alan

--
achidsey


"achidsey" wrote:

Excel Experts,

I would like to select a range offset to the right from the original range
based on the column headings.

My spreadsheet is similar to the following


A B C D
1 Acct Entry
2
3 4J6N 15
4 4J6N 15
5 4J6N 15
6 4J6N 15
7

Set St4J6N = Cells.Find(What:="4J6N").Select

Range("A100").Select

Set End4J6N = Cells.Find(What:="4J6N", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious)

Set rng4J6N = Range(St4J6N, End4J6N)

Set EntryS = Cells.Find(What:="Entry")

trd4J6N.Offset(, D1EntryS.Columns.Count - trd4J6N(1).Columns.Count).Select

End Sub

The final line isn't working. My goal is to select cells C3..C6.

What code will do this?

Thanks in advance.

Alan

--
achidsey

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
Return Column Heading based on value in row Lee New Users to Excel 2 May 21st 09 06:06 PM
Row filtering based on input box entry (column heading) Santed593 Excel Worksheet Functions 4 August 18th 05 12:35 AM
Select cells based on named Range and a column heading achidsey Excel Programming 3 August 12th 05 03:55 AM
Formatting a range based on contents of column/row heading Chris Crowe Excel Programming 0 August 20th 03 06:15 PM
Formatting a range based on contents of column/row heading Chris Excel Programming 1 August 20th 03 05:06 PM


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

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

About Us

"It's about Microsoft Excel"