Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel/VBA question

Status
Not open for further replies.

Ramy27

Technical User
Apr 26, 2005
63
GB
I have a question. The answer may be in Excel, if not, I need create VB function to do this.

When I type in a excel range (eg, A2:E34) in an Excel cell it should count the number of rows and columns in this range and write the results in another excel cell(s). Is it possible?



---------------------------------
"Good things are the enemies of the best things"
---------------------------------
 

Hi,

You can use the spreadsheet function COUNTA(). For your example...
[tt]
column count: =COUNTA(2:2)
row count: =COUNTA(A:A)
[/tt]


Skip,

[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue]
 


...that is assuming that each cell in the range in row 2 contains values and each cell in the range in column A contains values.

Skip,

[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue]
 
Thanks. But that is not my question.

What the user will actually enter in the excel CELL is something like the following

A1:D50

Then I need two functions in different cells that work out the number of rows and columns...*so the answers should be 50 and 4

---------------------------------
"Good things are the enemies of the best things"
---------------------------------
 
Have you actually tried looking in the help files ????

Took me about 5 seconds to find an appropriate function (ROWS) and then find a way to turn the string in the cell to a range reference

the answer you are looking for is

=ROWS(INDIRECT(A1))
=COLUMNS(INDIRECT(A1))

where "A1:D50" is in cell A1

Rgds, Geoff

Three things are certain. Death, taxes and lost data. DPlank is to blame

Please read FAQ222-2244 before you ask a question
 


Use Split function to divide the regerences.

analyse each referenc string to get the APLHA and NUMERIC parts. Use cell references to get the difference in COLUMNS like
Code:
NbrCols = Cells(1, SecondAlphaRef).Column - Cells(1, FirstAlphaRef).Column + 1



Skip,

[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue]
 
Skip - I think I prefer mine :p

Rgds, Geoff

Three things are certain. Death, taxes and lost data. DPlank is to blame

Please read FAQ222-2244 before you ask a question
 

Lets duke it out! ;-)

Skip,

[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue]
 
Given your love of word games, you can count on it :)

Rgds, Geoff

Three things are certain. Death, taxes and lost data. DPlank is to blame

Please read FAQ222-2244 before you ask a question
 
but FIRST, we gotta quaff a pint or two!

... and then, two being somewhat approximate, the count could ent up pr't' near anything!

Skip,

[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue]
 
thanks. That's exactly what i was looking for.

---------------------------------
"Good things are the enemies of the best things"
---------------------------------
 
LOL

As long as we leave on spea-King terms and get on royally, it'll all be fine. Having said that, maybe we should take this off to the squire-ing the circle forum.....

Rgds, Geoff

Three things are certain. Death, taxes and lost data. DPlank is to blame

Please read FAQ222-2244 before you ask a question
 

I'll leave footprince as I tread thusward.

Skip,

[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top