Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Function or a Sub?

I'll try to describe what this is about, but in QPW this
part was just a subroutine. This is the first part of a
bunch of postings I'll need to do relating to creating
some CSV files.

The purpose of this routine or function depending on the
suggestion is to scan a column

Sub CreateTaxCSVFile()
Range("Start").Offset(1, 0).Select 'create starting point'
Selection.CurrentRegion.Select 'to select a block of data'
Function or call to Howmanytype3()
----------------------------------
With the current region selected, I need to have the
function or sub to determine how many occurences of the
numeric value 3 occurs in the first column of this
selected region. The function needs to store that number
of occurences as a value for use later on in the macro.






  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default Function or a Sub?

Bruce,

This is a simple function to do it

Function HowMany(rng As Range, val)
Dim cell As Range
Dim cMatch As Long

For Each cell In rng
If cell.Value = val Then
cMatch = cMatch + 1
End If
Next
HowMany = cMatch
End Function

Call it like so
myNum = HowMany(Range("Start").Offset(1, 0).CurrentRegion,3)

--
HTH

-------

Bob Phillips
... looking out across Poole Harbour to the Purbecks


"Bruce Roberson" wrote in message
...
I'll try to describe what this is about, but in QPW this
part was just a subroutine. This is the first part of a
bunch of postings I'll need to do relating to creating
some CSV files.

The purpose of this routine or function depending on the
suggestion is to scan a column

Sub CreateTaxCSVFile()
Range("Start").Offset(1, 0).Select 'create starting point'
Selection.CurrentRegion.Select 'to select a block of data'
Function or call to Howmanytype3()
----------------------------------
With the current region selected, I need to have the
function or sub to determine how many occurences of the
numeric value 3 occurs in the first column of this
selected region. The function needs to store that number
of occurences as a value for use later on in the macro.








  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default Function or a Sub?

Try this and amend

Dim msg As String
Selection.CurrentRegion.Select ' optional, just need to select one cell
msg = MsgBox(Selection.Address)
msg = MsgBox(WorksheetFunction.CountIf(Range(Selection.A ddress), 3))


steve

"Bob Phillips" wrote in message
...
Bruce,

This is a simple function to do it

Function HowMany(rng As Range, val)
Dim cell As Range
Dim cMatch As Long

For Each cell In rng
If cell.Value = val Then
cMatch = cMatch + 1
End If
Next
HowMany = cMatch
End Function

Call it like so
myNum = HowMany(Range("Start").Offset(1, 0).CurrentRegion,3)

--
HTH

-------

Bob Phillips
... looking out across Poole Harbour to the Purbecks


"Bruce Roberson" wrote in message
...
I'll try to describe what this is about, but in QPW this
part was just a subroutine. This is the first part of a
bunch of postings I'll need to do relating to creating
some CSV files.

The purpose of this routine or function depending on the
suggestion is to scan a column

Sub CreateTaxCSVFile()
Range("Start").Offset(1, 0).Select 'create starting point'
Selection.CurrentRegion.Select 'to select a block of data'
Function or call to Howmanytype3()
----------------------------------
With the current region selected, I need to have the
function or sub to determine how many occurences of the
numeric value 3 occurs in the first column of this
selected region. The function needs to store that number
of occurences as a value for use later on in the macro.










  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default Function or a Sub?

Bruce,

As it turns out in this example range, there was only one
occurrence of the value 3 in this column. I tested the
watch by copying three more records in my data and then I
put a watch on "Howmany" in debug mode. The value
correctly showed 4 after I reran the macro. This was my
first time to add a watch. So is that all there is to
checking values of routines?


Not all there is, but part of it. You can use watches, you can print out
variables to the immediate window (Debug.Print myVar), you could write
output to a logfile, step through the code, use conditional compilation,
check the call stack, etc.. Lots of tools at your disposal, unfortunately
never enough.

Regards

Bob


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 Data Validation/Lookup function does function correcty Kirkey Excel Worksheet Functions 2 May 25th 09 09:22 PM
copy of excel file not showing formulal/function in the function b oaallam Excel Discussion (Misc queries) 4 September 6th 07 01:20 PM
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
Offset function with nested match function not finding host ss. MKunert Excel Worksheet Functions 1 March 21st 06 10:46 PM
Emulate Index/Match combo function w/ VBA custom function Spencer Hutton Excel Worksheet Functions 2 May 2nd 05 05:26 PM


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