Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Assistance with LASTROW function in VB

I need some help fixing some code. I'm still learning about VB so
hopefully, this will be easy for someone else.

I'm trying to create a pivot table from a list of cells with a variable
length. I'm trying to use the LASTROW function from Ron DeBruin and I can't
seem to get it to work. I want the LASTROW function to look at data in
worksheet "WorksheetNames"

Set SourceSh = ThisWorkbook.WorksheetNames
SourceSh.Name = "WorksheetNames"
Sheets("WorksheetNames").Select
Debug.Print Last
Last = LastRow(SourceSh)

Debug.Print Last
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"WorksheetNames!$A$1:$C$" & Last).CreatePivotTable
TableDestination:="", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10


Thanks in advance,

Barb Reinhardt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Assistance with LASTROW function in VB

What does LastRow do? Does it expect a worksheet or a range?

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Barb Reinhardt" wrote in message
...
I need some help fixing some code. I'm still learning about VB so
hopefully, this will be easy for someone else.

I'm trying to create a pivot table from a list of cells with a variable
length. I'm trying to use the LASTROW function from Ron DeBruin and I

can't
seem to get it to work. I want the LASTROW function to look at data in
worksheet "WorksheetNames"

Set SourceSh = ThisWorkbook.WorksheetNames
SourceSh.Name = "WorksheetNames"
Sheets("WorksheetNames").Select
Debug.Print Last
Last = LastRow(SourceSh)

Debug.Print Last
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"WorksheetNames!$A$1:$C$" & Last).CreatePivotTable
TableDestination:="", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10


Thanks in advance,

Barb Reinhardt



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Assistance with LASTROW function in VB

Also, is there a worksheet with a code name of Worksheetnames, judging by
the code it seems unlikely. You cannot set a worksheet variable to a
non-existent sheet.

And does the code error, or just not work? If the former, at which line?

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Barb Reinhardt" wrote in message
...
I need some help fixing some code. I'm still learning about VB so
hopefully, this will be easy for someone else.

I'm trying to create a pivot table from a list of cells with a variable
length. I'm trying to use the LASTROW function from Ron DeBruin and I

can't
seem to get it to work. I want the LASTROW function to look at data in
worksheet "WorksheetNames"

Set SourceSh = ThisWorkbook.WorksheetNames
SourceSh.Name = "WorksheetNames"
Sheets("WorksheetNames").Select
Debug.Print Last
Last = LastRow(SourceSh)

Debug.Print Last
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"WorksheetNames!$A$1:$C$" & Last).CreatePivotTable
TableDestination:="", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10


Thanks in advance,

Barb Reinhardt



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Assistance with LASTROW function in VB

Here is the DeBraun function LASTROW

Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function



"Bob Phillips" wrote:

Also, is there a worksheet with a code name of Worksheetnames, judging by
the code it seems unlikely. You cannot set a worksheet variable to a
non-existent sheet.

And does the code error, or just not work? If the former, at which line?

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Barb Reinhardt" wrote in message
...
I need some help fixing some code. I'm still learning about VB so
hopefully, this will be easy for someone else.

I'm trying to create a pivot table from a list of cells with a variable
length. I'm trying to use the LASTROW function from Ron DeBruin and I

can't
seem to get it to work. I want the LASTROW function to look at data in
worksheet "WorksheetNames"

Set SourceSh = ThisWorkbook.WorksheetNames
SourceSh.Name = "WorksheetNames"
Sheets("WorksheetNames").Select
Debug.Print Last
Last = LastRow(SourceSh)

Debug.Print Last
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"WorksheetNames!$A$1:$C$" & Last).CreatePivotTable
TableDestination:="", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10


Thanks in advance,

Barb Reinhardt




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Assistance with LASTROW function in VB

Your first couple of lines are confusing. If you already have a sheet with
a tab name of WorksheetNames then


Dim SourceSh as Worksheet
Set SourceSh = ThisWorkbook.Worksheet("WorksheetNames")
Sheets("WorksheetNames").Select
Debug.Print Last
Last = LastRow(SourceSh)
Debug.Print Last

If not and you want to rename it to WorksheetNames, then how are you
determining which sheet to work with?

--
Regards,
Tom Ogilvy

"Barb Reinhardt" wrote in message
...
I need some help fixing some code. I'm still learning about VB so
hopefully, this will be easy for someone else.

I'm trying to create a pivot table from a list of cells with a variable
length. I'm trying to use the LASTROW function from Ron DeBruin and I

can't
seem to get it to work. I want the LASTROW function to look at data in
worksheet "WorksheetNames"

Set SourceSh = ThisWorkbook.WorksheetNames
SourceSh.Name = "WorksheetNames"
Sheets("WorksheetNames").Select
Debug.Print Last
Last = LastRow(SourceSh)

Debug.Print Last
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"WorksheetNames!$A$1:$C$" & Last).CreatePivotTable
TableDestination:="", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10


Thanks in advance,

Barb Reinhardt





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Assistance with LASTROW function in VB

I get error

Method or data member not found

on this line

Set SourceSh = ThisWorkbook.Worksheet("WorksheetNames")

The source code is in personal.xls and I'm using another workbook.

"Tom Ogilvy" wrote:

Your first couple of lines are confusing. If you already have a sheet with
a tab name of WorksheetNames then


Dim SourceSh as Worksheet
Set SourceSh = ThisWorkbook.Worksheet("WorksheetNames")
Sheets("WorksheetNames").Select
Debug.Print Last
Last = LastRow(SourceSh)
Debug.Print Last

If not and you want to rename it to WorksheetNames, then how are you
determining which sheet to work with?

--
Regards,
Tom Ogilvy

"Barb Reinhardt" wrote in message
...
I need some help fixing some code. I'm still learning about VB so
hopefully, this will be easy for someone else.

I'm trying to create a pivot table from a list of cells with a variable
length. I'm trying to use the LASTROW function from Ron DeBruin and I

can't
seem to get it to work. I want the LASTROW function to look at data in
worksheet "WorksheetNames"

Set SourceSh = ThisWorkbook.WorksheetNames
SourceSh.Name = "WorksheetNames"
Sheets("WorksheetNames").Select
Debug.Print Last
Last = LastRow(SourceSh)

Debug.Print Last
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"WorksheetNames!$A$1:$C$" & Last).CreatePivotTable
TableDestination:="", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10


Thanks in advance,

Barb Reinhardt




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Assistance with LASTROW function in VB

either

Set SourceSh = ActiveWorkbook.Worksheet("WorksheetNames")

or reference a specific open workbook

Set SourceSh = Workbooks("Myworkbook.xls").Worksheets("WorksheetN ames")

However, since you want to select the sheet, I would assume you are working
with the activeworkbook. If not, then instead of

Sheets("WorksheetNames").Select

( or even SourceSh.Select )

use
Application.Goto Reference:=SourceSh



--
Regards,
Tom Ogilvy


"Barb Reinhardt" wrote in message
...
I get error

Method or data member not found

on this line

Set SourceSh = ThisWorkbook.Worksheet("WorksheetNames")

The source code is in personal.xls and I'm using another workbook.

"Tom Ogilvy" wrote:

Your first couple of lines are confusing. If you already have a sheet

with
a tab name of WorksheetNames then


Dim SourceSh as Worksheet
Set SourceSh = ThisWorkbook.Worksheet("WorksheetNames")
Sheets("WorksheetNames").Select
Debug.Print Last
Last = LastRow(SourceSh)
Debug.Print Last

If not and you want to rename it to WorksheetNames, then how are you
determining which sheet to work with?

--
Regards,
Tom Ogilvy

"Barb Reinhardt" wrote in

message
...
I need some help fixing some code. I'm still learning about VB so
hopefully, this will be easy for someone else.

I'm trying to create a pivot table from a list of cells with a

variable
length. I'm trying to use the LASTROW function from Ron DeBruin and

I
can't
seem to get it to work. I want the LASTROW function to look at data

in
worksheet "WorksheetNames"

Set SourceSh = ThisWorkbook.WorksheetNames
SourceSh.Name = "WorksheetNames"
Sheets("WorksheetNames").Select
Debug.Print Last
Last = LastRow(SourceSh)

Debug.Print Last
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase,

SourceData:= _
"WorksheetNames!$A$1:$C$" & Last).CreatePivotTable
TableDestination:="", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10


Thanks in advance,

Barb Reinhardt






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Assistance with LASTROW function in VB

It worked with this

Set SourceSh = ActiveWorkbook.WorksheetS("WorksheetNames")


"Tom Ogilvy" wrote:

either

Set SourceSh = ActiveWorkbook.Worksheet("WorksheetNames")

or reference a specific open workbook

Set SourceSh = Workbooks("Myworkbook.xls").Worksheets("WorksheetN ames")

However, since you want to select the sheet, I would assume you are working
with the activeworkbook. If not, then instead of

Sheets("WorksheetNames").Select

( or even SourceSh.Select )

use
Application.Goto Reference:=SourceSh



--
Regards,
Tom Ogilvy


"Barb Reinhardt" wrote in message
...
I get error

Method or data member not found

on this line

Set SourceSh = ThisWorkbook.Worksheet("WorksheetNames")

The source code is in personal.xls and I'm using another workbook.

"Tom Ogilvy" wrote:

Your first couple of lines are confusing. If you already have a sheet

with
a tab name of WorksheetNames then


Dim SourceSh as Worksheet
Set SourceSh = ThisWorkbook.Worksheet("WorksheetNames")
Sheets("WorksheetNames").Select
Debug.Print Last
Last = LastRow(SourceSh)
Debug.Print Last

If not and you want to rename it to WorksheetNames, then how are you
determining which sheet to work with?

--
Regards,
Tom Ogilvy

"Barb Reinhardt" wrote in

message
...
I need some help fixing some code. I'm still learning about VB so
hopefully, this will be easy for someone else.

I'm trying to create a pivot table from a list of cells with a

variable
length. I'm trying to use the LASTROW function from Ron DeBruin and

I
can't
seem to get it to work. I want the LASTROW function to look at data

in
worksheet "WorksheetNames"

Set SourceSh = ThisWorkbook.WorksheetNames
SourceSh.Name = "WorksheetNames"
Sheets("WorksheetNames").Select
Debug.Print Last
Last = LastRow(SourceSh)

Debug.Print Last
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase,

SourceData:= _
"WorksheetNames!$A$1:$C$" & Last).CreatePivotTable
TableDestination:="", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10


Thanks in advance,

Barb Reinhardt






  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Assistance with LASTROW function in VB

Yep, sometimes I make typos. Glad you figured it out.

--
Regards,
Tom Ogilvy


"Barb Reinhardt" wrote in message
...
It worked with this

Set SourceSh = ActiveWorkbook.WorksheetS("WorksheetNames")


"Tom Ogilvy" wrote:

either

Set SourceSh = ActiveWorkbook.Worksheet("WorksheetNames")

or reference a specific open workbook

Set SourceSh = Workbooks("Myworkbook.xls").Worksheets("WorksheetN ames")

However, since you want to select the sheet, I would assume you are

working
with the activeworkbook. If not, then instead of

Sheets("WorksheetNames").Select

( or even SourceSh.Select )

use
Application.Goto Reference:=SourceSh



--
Regards,
Tom Ogilvy


"Barb Reinhardt" wrote in

message
...
I get error

Method or data member not found

on this line

Set SourceSh = ThisWorkbook.Worksheet("WorksheetNames")

The source code is in personal.xls and I'm using another workbook.

"Tom Ogilvy" wrote:

Your first couple of lines are confusing. If you already have a

sheet
with
a tab name of WorksheetNames then


Dim SourceSh as Worksheet
Set SourceSh = ThisWorkbook.Worksheet("WorksheetNames")
Sheets("WorksheetNames").Select
Debug.Print Last
Last = LastRow(SourceSh)
Debug.Print Last

If not and you want to rename it to WorksheetNames, then how are you
determining which sheet to work with?

--
Regards,
Tom Ogilvy

"Barb Reinhardt" wrote in

message
...
I need some help fixing some code. I'm still learning about VB

so
hopefully, this will be easy for someone else.

I'm trying to create a pivot table from a list of cells with a

variable
length. I'm trying to use the LASTROW function from Ron DeBruin

and
I
can't
seem to get it to work. I want the LASTROW function to look at

data
in
worksheet "WorksheetNames"

Set SourceSh = ThisWorkbook.WorksheetNames
SourceSh.Name = "WorksheetNames"
Sheets("WorksheetNames").Select
Debug.Print Last
Last = LastRow(SourceSh)

Debug.Print Last
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase,

SourceData:= _
"WorksheetNames!$A$1:$C$" & Last).CreatePivotTable
TableDestination:="", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10


Thanks in advance,

Barb Reinhardt








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
Need assistance with how or even if this is possible (function) Marty Excel Worksheet Functions 8 February 16th 10 05:49 PM
Lastrow - function not defined seed Excel Discussion (Misc queries) 2 August 7th 08 06:34 PM
LastRow function - #VALUE slc[_17_] Excel Programming 4 September 1st 05 09:47 PM
'LastRow' Function not working Randy Reese[_2_] Excel Programming 4 July 17th 04 03:44 AM
Go to lastrow using other column's lastrow stakar[_14_] Excel Programming 5 April 16th 04 03:42 PM


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