Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default Adding a column to a table

I'm trying to add a column to a table in excel using vba. Here is the code I
have.

Dim tblData As ListObject
Dim calendarWeek As ListColumn

tblData = Sheets("Sheet1").ListObjects("Table1") <- Error Here
calendarWeek = tblTop8Issue.ListColumns.Add
calendarWeek.Name = "Calendar Week"
calendarWeek.DataBodyRange = "WEEKNUM([Date])"

I get an error on the first line saying Invalid Use of Property...Please help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Adding a column to a table

Since you're trying to set the variable equal to an object, I believe you
need to use the SET statement, such as:

Set tblData = Sheets("Sheet1").ListObjects("Table1")

Try that out...

--
Happy calculating!

If you like this answer, please click ''Yes.''




"Brad" wrote:

I'm trying to add a column to a table in excel using vba. Here is the code I
have.

Dim tblData As ListObject
Dim calendarWeek As ListColumn

tblData = Sheets("Sheet1").ListObjects("Table1") <- Error Here
calendarWeek = tblTop8Issue.ListColumns.Add
calendarWeek.Name = "Calendar Week"
calendarWeek.DataBodyRange = "WEEKNUM([Date])"

I get an error on the first line saying Invalid Use of Property...Please help

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default Adding a column to a table

that worked great, thanks. Getting an error now on the last line
calendarWeek.DataBodyRange = "=WEEKNUM([Date])"
any ideas?

"GSnyder" wrote:

Since you're trying to set the variable equal to an object, I believe you
need to use the SET statement, such as:

Set tblData = Sheets("Sheet1").ListObjects("Table1")

Try that out...

--
Happy calculating!

If you like this answer, please click ''Yes.''




"Brad" wrote:

I'm trying to add a column to a table in excel using vba. Here is the code I
have.

Dim tblData As ListObject
Dim calendarWeek As ListColumn

tblData = Sheets("Sheet1").ListObjects("Table1") <- Error Here
calendarWeek = tblTop8Issue.ListColumns.Add
calendarWeek.Name = "Calendar Week"
calendarWeek.DataBodyRange = "WEEKNUM([Date])"

I get an error on the first line saying Invalid Use of Property...Please help

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Adding a column to a table

Are you looking for the current week number? If so, weeknum(now()) may work
instead. I don't think it'll recognize [Date].

--
Happy calculating!

If you like this answer, please click ''Yes.''




"Brad" wrote:

that worked great, thanks. Getting an error now on the last line
calendarWeek.DataBodyRange = "=WEEKNUM([Date])"
any ideas?

"GSnyder" wrote:

Since you're trying to set the variable equal to an object, I believe you
need to use the SET statement, such as:

Set tblData = Sheets("Sheet1").ListObjects("Table1")

Try that out...

--
Happy calculating!

If you like this answer, please click ''Yes.''




"Brad" wrote:

I'm trying to add a column to a table in excel using vba. Here is the code I
have.

Dim tblData As ListObject
Dim calendarWeek As ListColumn

tblData = Sheets("Sheet1").ListObjects("Table1") <- Error Here
calendarWeek = tblTop8Issue.ListColumns.Add
calendarWeek.Name = "Calendar Week"
calendarWeek.DataBodyRange = "WEEKNUM([Date])"

I get an error on the first line saying Invalid Use of Property...Please help

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default Adding a column to a table

Actually I had to type out the whole thing like

=WEEKNUM(Table1[#ThisRow],[Date])

thanks for all the help

"GSnyder" wrote:

Are you looking for the current week number? If so, weeknum(now()) may work
instead. I don't think it'll recognize [Date].

--
Happy calculating!

If you like this answer, please click ''Yes.''




"Brad" wrote:

that worked great, thanks. Getting an error now on the last line
calendarWeek.DataBodyRange = "=WEEKNUM([Date])"
any ideas?

"GSnyder" wrote:

Since you're trying to set the variable equal to an object, I believe you
need to use the SET statement, such as:

Set tblData = Sheets("Sheet1").ListObjects("Table1")

Try that out...

--
Happy calculating!

If you like this answer, please click ''Yes.''




"Brad" wrote:

I'm trying to add a column to a table in excel using vba. Here is the code I
have.

Dim tblData As ListObject
Dim calendarWeek As ListColumn

tblData = Sheets("Sheet1").ListObjects("Table1") <- Error Here
calendarWeek = tblTop8Issue.ListColumns.Add
calendarWeek.Name = "Calendar Week"
calendarWeek.DataBodyRange = "WEEKNUM([Date])"

I get an error on the first line saying Invalid Use of Property...Please 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
Pivot Table and adding a % column, that is not in original data MarkArtillery Excel Discussion (Misc queries) 3 February 23rd 10 06:21 PM
Adding a column to an Excel table Suzi-Q Excel Discussion (Misc queries) 2 September 4th 09 10:04 PM
pivot table; adding kolomns to the base-table afterwards overjaxed Excel Programming 2 September 15th 08 04:30 PM
Column Chart - Adding text in the column in Excel 2007 Jennifer Charts and Charting in Excel 2 July 26th 08 02:58 PM
Adding a Custom Column based on an existing Column (EXPERT) Sean W. Excel Worksheet Functions 4 January 16th 08 04:24 PM


All times are GMT +1. The time now is 03:00 AM.

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"