Solved

How do I count the number of columns in an Excel table in VBA ?

Posted on 2013-11-21
4
298 Views
Last Modified: 2013-11-21
Hi,

I'm trying to count the number of columns in a table in an Excel 2010 VBA application  called 'Sales' but getting a 'Variable not defined' error.

Do tables have to be defined separately from sheets ? If so, how ?

My code is as follows .....

Dim lgColumnCount As Long
lgColumnCount = Range(Sales).Columns.Count

Thanks
0
Comment
Question by:Tocogroup
  • 3
4 Comments
 
LVL 4

Expert Comment

by:yuppydu
ID: 39665230
I think you are missing some data in your command line. First of all it should be Range("Sales") and you are also not saying  which sheet you are referring to...
Can you share the workbook?
0
 
LVL 4

Accepted Solution

by:
yuppydu earned 500 total points
ID: 39665238
Try this

lgColumnCount= Sheet1.Range("Sales").Columns.Count

replace Sheet1 with whatever sheet the table is
0
 

Author Closing Comment

by:Tocogroup
ID: 39665250
Ah ! It was that simple. Just the quotes were missing.
Thanks for the solution.
0
 
LVL 4

Expert Comment

by:yuppydu
ID: 39665254
Well sometimes the simplest things make a big difference....
Have a good day
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now