Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default naming an undetermined range in a new worksheet via vba


I'm stumped on the fastest/cleanest way to do the following:

After copying in an entire worksheet from a source workbook into my
open workbook in vba, I would like to name a range of cells on that
worksheet just copied in.

I know that the range I want to name will _begin_ just below a cell
with the keyword Ticker in it (that Ticker keyword cell is currently
A21). Where the range ends will always be variable.

I don't know how to name a range in VB and I don't know how to find the
last cell that has data. In this example the last cell is FK136 and
then there are some blank cells and then in FK140 there is a shaded
cell where there will somtimes be data. But whether it is row 140 or
220 or 180 it will always be different. I can count on column FK right
now, but in the future, who knows.

Any suggestions?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default naming an undetermined range in a new worksheet via vba

Sub SubFindIt()
Dim RealLastRow As Long
Dim RealLastColumn As Long
Dim rng as Range, rng1 as Range
dim rng2 as Range, sStr as String

sStr = "ticker"
Set rng = Cells.Find(What:=sStr, _
After:=Range("IV65536"), _
LookIn:=xlConstatns, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then

On Error Resume Next
RealLastRow = _
Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
RealLastColumn = _
Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column
set rng1 = Cells(RealLastRow, RealLastColumn)
On Error goto 0
if not rng1 is nothing then
set rng2 = Range(rng,rng1)
rng2.Name = "MyData"
End if
else
msgbox "Ticker not found"
End If
End Sub

--
Regards,
Tom Ogilvy

"nycjdc" wrote:


I'm stumped on the fastest/cleanest way to do the following:

After copying in an entire worksheet from a source workbook into my
open workbook in vba, I would like to name a range of cells on that
worksheet just copied in.

I know that the range I want to name will _begin_ just below a cell
with the keyword Ticker in it (that Ticker keyword cell is currently
A21). Where the range ends will always be variable.

I don't know how to name a range in VB and I don't know how to find the
last cell that has data. In this example the last cell is FK136 and
then there are some blank cells and then in FK140 there is a shaded
cell where there will somtimes be data. But whether it is row 140 or
220 or 180 it will always be different. I can count on column FK right
now, but in the future, who knows.

Any suggestions?


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
Summing values from an undetermined number of sheet smaruzzi Excel Worksheet Functions 3 April 6th 07 08:16 PM
Naming Sheets using a range in another worksheet gazza Excel Worksheet Functions 3 September 19th 06 01:02 PM
Help on Vlookup for Undetermined Range sylink Excel Programming 3 October 17th 05 08:58 PM
Summing undetermined colums RJH Excel Programming 7 December 23rd 03 07:01 PM
Code for naming worksheet name range?? Sandy[_3_] Excel Programming 2 September 7th 03 04:49 AM


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