PC Review


Reply
Thread Tools Rate Thread

Calling a function within a macro

 
 
AmyHomewood
Guest
Posts: n/a
 
      24th Sep 2008
Hi,

I have a worksheet called SDB which consists of a row (1) of column headings
and then a row (2) of cell values/references/formulas etc. a second sheet
called Data in the same workbook holds data values from another source which
need to be organised/formatted in a diferent way (i.e. this is what the SDB
sheet does). My macro called SDB_copy selects row 2 of SDB and copies down to
the last lastrow of data (the lastrow is found using the following line of
code: lastrow = Sheets("Data").Cells(Cells.Rows.Count, "A").End(xlUp).row)

SDB has some cells which are conditionally formatted to have a red
background on certain conditions. I have a couple of functions that 1.
identify the colour index (CFColorindex) and 2. count the number of cells
which have the specified condition (CFColorCount).

I can call the functions from a cell in the worksheet using:
=CFColorCount(Z2:Z76,3)
which gives the right answer.

What I want to do is call the function from my SDB_copy macro and display
the result in a message box, for example

MsgBox("Please correct errors -" answer)

So far I have tried various ways of calling the function from within my
macro, such as:

Dim Res As Variant
Res = Application.Function.CFColorCount("Z2:Z76", 3)
MsgBox ("Please Rectify All Highlighted Records - " & Res)

but when I try to run the macro I get an error suggesting that the : in the
range is unexpected.

I would also like to be able to use the lastrow facility such that the range
to be counted is ("A2:A" & lastrow).

I know this is probably really simple but I just cant get the coding right,
all help is gratefully received!

I apologise if my explanation is a bit long, thanks in advance
Kind regards,
Amy
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
calling module function from macro =?Utf-8?B?VE1HcmVlbg==?= Microsoft Access Macros 3 8th Mar 2006 12:17 AM
Calling an Excel function from a VBA macro Steven M (remove wax and invalid to reply) Microsoft Excel Programming 3 19th Jan 2006 11:01 AM
Calling up the Solver function in a VBA macro Wayne Stewart Microsoft Excel Programming 7 28th Jan 2004 04:21 PM
calling a function in another database from within a macro Andy Georges Microsoft Access Macros 1 6th Nov 2003 12:49 AM
Re: Calling a macro from within an IF function Paul Microsoft Excel Worksheet Functions 0 26th Sep 2003 09:03 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:18 PM.