Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Finding the last cell in a range

I have a few macros that select a range of cells. I
occassionally delete the contents of the RWA Data sheet
and paste in new information that contains the same number
of columns, but the number of rows will always change.
The follwing is an example of some code from one of my
macros. I will always be selecting " 'RWA Data' !R1C1:
but the last row will change. What code can I add that
will look at the last cell in a list that my cursor is in?

Thanks much,
Alex


Range("E14").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase,
SourceData:= _
"'RWA Data'!R1C1:R3502C19").CreatePivotTable
TableDestination:="", TableName _
:="PivotTable1"
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Finding the last cell in a range

Do as follow:
Use a column that will have value in every row.
Assume column A
range("A2").select
ActiveCell.End(xlDown).Select
LastRow = ActiveCell.Row
SourceData:= _
"'RWA Data'!R1C1:R" & LastRow

& "C19").CreatePivotTable
range("A2').select

This should work

Andres
-----Original Message-----
I have a few macros that select a range of cells. I
occassionally delete the contents of the RWA Data sheet
and paste in new information that contains the same

number
of columns, but the number of rows will always change.
The follwing is an example of some code from one of my
macros. I will always be selecting " 'RWA Data' !R1C1:
but the last row will change. What code can I add that
will look at the last cell in a list that my cursor is in?

Thanks much,
Alex


Range("E14").Select
ActiveWorkbook.PivotCaches.Add

(SourceType:=xlDatabase,
SourceData:= _
"'RWA Data'!R1C1:R3502C19").CreatePivotTable
TableDestination:="", TableName _
:="PivotTable1"
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Finding the last cell in a range

Get last row with

cRow = Cells(Rows.Count,"A").End(xlUp).Row

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Alex" wrote in message
...
I have a few macros that select a range of cells. I
occassionally delete the contents of the RWA Data sheet
and paste in new information that contains the same number
of columns, but the number of rows will always change.
The follwing is an example of some code from one of my
macros. I will always be selecting " 'RWA Data' !R1C1:
but the last row will change. What code can I add that
will look at the last cell in a list that my cursor is in?

Thanks much,
Alex


Range("E14").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase,
SourceData:= _
"'RWA Data'!R1C1:R3502C19").CreatePivotTable
TableDestination:="", TableName _
:="PivotTable1"



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 85
Default Finding the last cell in a range

Use the following function:
Function LastCell(ws As Worksheet) As Range
Dim LastRow&, LastCol%

' Error-handling is here in case there is not any
' data in the worksheet

On Error Resume Next

With ws

' Find the last real row

LastRow& = .Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row

' Find the last real column

LastCol% = .Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column

End With

' Finally, initialize a Range object variable for
' the last populated row.

Set LastCell = ws.Cells(LastRow&, LastCol%)

End Function

then LastCell('RWA Data').row should give you the last row that you require

"Alex" wrote in message
...
I have a few macros that select a range of cells. I
occassionally delete the contents of the RWA Data sheet
and paste in new information that contains the same number
of columns, but the number of rows will always change.
The follwing is an example of some code from one of my
macros. I will always be selecting " 'RWA Data' !R1C1:
but the last row will change. What code can I add that
will look at the last cell in a list that my cursor is in?

Thanks much,
Alex


Range("E14").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase,
SourceData:= _
"'RWA Data'!R1C1:R3502C19").CreatePivotTable
TableDestination:="", TableName _
:="PivotTable1"



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
An old chestnut: finding the last cell in a range maninashed Excel Worksheet Functions 10 October 4th 09 05:13 PM
Finding Cell Outside Of Range Minitman Excel Worksheet Functions 3 April 15th 08 06:34 AM
Finding the bottom non-blank cell in a range Fenneth Excel Discussion (Misc queries) 7 July 6th 06 06:05 PM
Finding first (end of range) empty cell Alesandro Senerchia Excel Programming 4 May 20th 04 02:36 AM
Finding if a cell is within a Range [email protected] Excel Programming 2 October 31st 03 09:57 PM


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