Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default excel vba - COUNTIF syntax

Hi All,

I got a question on COUNTIF.

'keylength = CInt(KeyLengthComboBox.Value)

keylength = 3
myCol = 0

For x = 1 To keylength
For y = 1 to 26
Sheet10.Cells(y, x) = "=COUNTIF(sheet9!$A:$A,CHAR(66))"
Next y
Next x


Is it possible to replace the $A:$A part to a variable x which
represents the whole column 1 to 3 respectively and
also replace the CHAR(66) to CHAR(64+y)?

If it's possible, what is the correct syntax for doing it?

Many thanks.

did

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default excel vba - COUNTIF syntax


Sheet10.Cells(y, x) = "=COUNTIF(sheet9!$A:$A,CHAR(" & 64 + y & "))"

might work nicely.


"paku <" wrote:

Hi All,

I got a question on COUNTIF.

'keylength = CInt(KeyLengthComboBox.Value)

keylength = 3
myCol = 0

For x = 1 To keylength
For y = 1 to 26
Sheet10.Cells(y, x) = "=COUNTIF(sheet9!$A:$A,CHAR(66))"
Next y
Next x

Is it possible to replace the $A:$A part to a variable x which
represents the whole column 1 to 3 respectively and
also replace the CHAR(66) to CHAR(64+y)?

If it's possible, what is the correct syntax for doing it?

Many thanks.

dido

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default excel vba - COUNTIF syntax

thanks, dave but how about the $A:$A?
can it be replaced with variable x?
i want it to count every occurence in WHOLE column of x


e.g.Sheet10.Cells(y, x) = "=COUNTIF(sheet9!$A:$A,CHAR(" & 64 + y
"))"

thanks!

did

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default excel vba - COUNTIF syntax

Oops. Missed that part. There are lots of ways. I like to set a range
variable to the range and let excel worry about the syntax (in the cell itself):


Option Explicit
Sub testme()

Dim y As Long
Dim x As Long
Dim myRng As Range

x = 1
y = 1

Set myRng = Sheet9.Columns(x)

Sheet10.Cells(y, x) = "=COUNTIF(" & myRng.Address(external:=True) _
& ",CHAR(" & 64 + y &
"))"

End Sub

Then I don't have to worry about someone changing the name of the worksheet,
too! (Not many know how to modify the codename (sheet10). But lots could
change that worksheet name in the tab (sheet9).


"paku <" wrote:

thanks, dave but how about the $A:$A?
can it be replaced with variable x?
i want it to count every occurence in WHOLE column of x

e.g.Sheet10.Cells(y, x) = "=COUNTIF(sheet9!$A:$A,CHAR(" & 64 + y &
"))"

thanks!

dido

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson

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
excel formula syntax Barbara Excel Worksheet Functions 1 January 12th 10 02:49 PM
vba syntax for excel object TKoel Excel Discussion (Misc queries) 1 February 10th 09 11:34 PM
syntax for countif when cells fall within a numerical range Tom L Excel Worksheet Functions 5 May 31st 08 03:22 AM
What is the syntax for the IF formula in Excel? Christina Excel Worksheet Functions 5 October 10th 05 10:39 PM
Excel Rank syntax Jingtao Excel Worksheet Functions 1 February 28th 05 08:56 AM


All times are GMT +1. The time now is 11:01 AM.

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"