Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Selection range to last non empty cell

Does anyone know how I could write a macro to select range from A3 to value
"TEAM"?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Selection range to last non empty cell

Maybe...

Option Explicit
Sub testme2()

Dim FirstCell As Range
Dim SecondCell As Range
Dim RngToSearch As Range

With ActiveSheet
Set FirstCell = .Range("a3")
Set RngToSearch = .Range("a3", .Cells(.Rows.Count, "A").End(xlUp))

With RngToSearch
Set SecondCell = .Cells.Find(what:="Team", _
after:=.Cells(1), lookat:=xlWhole, _
searchorder:=xlByRows, searchdirection:=xlNext, _
MatchCase:=False)

If SecondCell Is Nothing Then
'not found
Set SecondCell = FirstCell
End If
End With

.Range(FirstCell, SecondCell).Select
End With

End Sub




Jaan wrote:

Does anyone know how I could write a macro to select range from A3 to value
"TEAM"?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Selection range to last non empty cell

Try this

Sub test()
Dim rng As Range
With Sheets("Sheet1").Range("A3:A" & Rows.Count)
Set rng = .Find(What:="Team", _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then
Sheets("Sheet1").Range("A3:A" & rng.Row).Select
Else
MsgBox "Nothing found"
End If
End With
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Jaan" wrote in message ...
Does anyone know how I could write a macro to select range from A3 to value
"TEAM"?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Selection range to last non empty cell

Hi

Thanks. This working.



"Dave Peterson" kirjutas:

Maybe...

Option Explicit
Sub testme2()

Dim FirstCell As Range
Dim SecondCell As Range
Dim RngToSearch As Range

With ActiveSheet
Set FirstCell = .Range("a3")
Set RngToSearch = .Range("a3", .Cells(.Rows.Count, "A").End(xlUp))

With RngToSearch
Set SecondCell = .Cells.Find(what:="Team", _
after:=.Cells(1), lookat:=xlWhole, _
searchorder:=xlByRows, searchdirection:=xlNext, _
MatchCase:=False)

If SecondCell Is Nothing Then
'not found
Set SecondCell = FirstCell
End If
End With

.Range(FirstCell, SecondCell).Select
End With

End Sub




Jaan wrote:

Does anyone know how I could write a macro to select range from A3 to value
"TEAM"?


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Selection range to last non empty cell

Hi

and this working
Thanks!

"Ron de Bruin" kirjutas:

Try this

Sub test()
Dim rng As Range
With Sheets("Sheet1").Range("A3:A" & Rows.Count)
Set rng = .Find(What:="Team", _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then
Sheets("Sheet1").Range("A3:A" & rng.Row).Select
Else
MsgBox "Nothing found"
End If
End With
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Jaan" wrote in message ...
Does anyone know how I could write a macro to select range from A3 to value
"TEAM"?




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
If cell not empty, then display from range puiuluipui Excel Discussion (Misc queries) 7 October 3rd 09 08:01 PM
select first empty cell in a range Shawn Excel Programming 2 September 13th 05 12:14 AM
Picking up the last non-empty cell in a given range zhj23 Excel Discussion (Misc queries) 4 June 1st 05 12:34 AM
Grabbing the last Non-empty cell in a range Arlen Excel Discussion (Misc queries) 2 January 22nd 05 05:15 PM
Finding first (end of range) empty cell Alesandro Senerchia Excel Programming 4 May 20th 04 02:36 AM


All times are GMT +1. The time now is 12:24 PM.

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"