Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Selecting just my text

I need to find the bottom of my text. I have added some text and deleted it
and when I do this:

Range("A1").Select
ActiveCell.SpecialCells(xlLastCell).Select
ActiveCell.Offset(1, -10).Range("A1").Select

it goes to the bottom of wherever I have had data even if it has been
deleted as in, if I delete rows 10 to 20, the code above will still take me
to row 20 when I want to go to row 10 where my text is. How can I get around
this?

All help greatly appreciated.

J
--
www.brightfuture.ca/bright
My email address can be found on my site.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Selecting just my text

Here is a function that returns the true last cell on the sheet. Execute Sub
Test() to give it a try...

Sub test()
LastCell().Select
End Sub

Public Function LastCell(Optional ByVal wks As Worksheet) As Range
Dim lngLastRow As Long
Dim intLastColumn As Integer

If wks Is Nothing Then Set wks = ActiveSheet
On Error Resume Next
lngLastRow = wks.Cells.Find(What:="*", _
After:=wks.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
intLastColumn = wks.Cells.Find(What:="*", _
After:=wks.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0
If lngLastRow = 0 Then
lngLastRow = 1
intLastColumn = 1
End If
Set LastCell = wks.Cells(lngLastRow, intLastColumn)

End Function

--
HTH...

Jim Thomlinson


"Johnny Bright" wrote:

I need to find the bottom of my text. I have added some text and deleted it
and when I do this:

Range("A1").Select
ActiveCell.SpecialCells(xlLastCell).Select
ActiveCell.Offset(1, -10).Range("A1").Select

it goes to the bottom of wherever I have had data even if it has been
deleted as in, if I delete rows 10 to 20, the code above will still take me
to row 20 when I want to go to row 10 where my text is. How can I get around
this?

All help greatly appreciated.

J
--
www.brightfuture.ca/bright
My email address can be found on my site.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Selecting just my text

That worked perfectly! Thanks so much!

John
--
www.brightfuture.ca/bright
My email address can be found on my site.


"Jim Thomlinson" wrote:

Here is a function that returns the true last cell on the sheet. Execute Sub
Test() to give it a try...

Sub test()
LastCell().Select
End Sub

Public Function LastCell(Optional ByVal wks As Worksheet) As Range
Dim lngLastRow As Long
Dim intLastColumn As Integer

If wks Is Nothing Then Set wks = ActiveSheet
On Error Resume Next
lngLastRow = wks.Cells.Find(What:="*", _
After:=wks.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
intLastColumn = wks.Cells.Find(What:="*", _
After:=wks.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0
If lngLastRow = 0 Then
lngLastRow = 1
intLastColumn = 1
End If
Set LastCell = wks.Cells(lngLastRow, intLastColumn)

End Function

--
HTH...

Jim Thomlinson


"Johnny Bright" wrote:

I need to find the bottom of my text. I have added some text and deleted it
and when I do this:

Range("A1").Select
ActiveCell.SpecialCells(xlLastCell).Select
ActiveCell.Offset(1, -10).Range("A1").Select

it goes to the bottom of wherever I have had data even if it has been
deleted as in, if I delete rows 10 to 20, the code above will still take me
to row 20 when I want to go to row 10 where my text is. How can I get around
this?

All help greatly appreciated.

J
--
www.brightfuture.ca/bright
My email address can be found on my site.

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
selecting certain text in long row of text Jonathan Excel Worksheet Functions 1 August 27th 05 12:26 AM
Selecting text only Sethaholic[_12_] Excel Programming 0 July 13th 05 08:52 PM
Selecting text steve Excel Programming 2 June 23rd 05 02:02 PM
Selecting All Text in TextBox DRKML Excel Programming 1 April 12th 05 12:07 PM
Selecting text in cells & half of the Selected Text to be underLine Manish Singh Excel Programming 3 October 14th 04 07:34 PM


All times are GMT +1. The time now is 05:42 PM.

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"