Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Select range on a worksheet

Hi all.

I do a lot of downloads with CSV files that I pull into Excel and then
have to format, so I wrote a macro that does 99% of the formatting I
need to do, but I'm having the darndest time getting a macro to select
the whole range that has values in it starting at Cell A1 and going to
the last cell... which might be F500, Q1250, or whatever, depending on
the worksheet. All I want to do is select the whole range and then
put borders on the cells.

Any help?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Select range on a worksheet

Give this a try...

Sub SelectRange() 'Run me
Range("A1", 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


"Jim" wrote:

Hi all.

I do a lot of downloads with CSV files that I pull into Excel and then
have to format, so I wrote a macro that does 99% of the formatting I
need to do, but I'm having the darndest time getting a macro to select
the whole range that has values in it starting at Cell A1 and going to
the last cell... which might be F500, Q1250, or whatever, depending on
the worksheet. All I want to do is select the whole range and then
put borders on the cells.

Any help?

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
select range of specific hidden worksheet of closed protected work JASelep Excel Programming 0 September 6th 07 01:56 PM
Activate and Select range/worksheet zhj23 Excel Programming 6 July 14th 07 01:07 PM
IF statement to activate worksheet & select Range MentalDrow Excel Programming 1 June 19th 06 08:20 PM
use an input box to select a range and copy to another worksheet Paul Excel Programming 6 April 11th 06 06:23 PM
Using Dialog to select a Workbook, Worksheet and Range Tony Starr[_3_] Excel Programming 2 June 24th 05 07:21 AM


All times are GMT +1. The time now is 04:53 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"