#1   Report Post  
Bill Martin -- (Remove NOSPAM from address)
 
Posts: n/a
Default VBA Cell Addressing

I've got what must be a simple addressing problem but it's driving me
crazy. I can create a simple macro that just looks like:

Sub TestMacro
ActiveCell(1,2) = "Done"
End Sub

And it does exactly what I'd expect. It plugs a value into the cell to
the right of the cursor. Now if I try to do the similar thing with a
Function instead of a Macro it just refuses to co-operate. For example:

Function TestFunct(CellRef)
ActiveCell(1,2) = "Done"
End Function

This will croak with a #VALUE! error. Likewise:

Function TestFunct(CellRef)
CellRef(1,2) = "Done"
End Function

Also refuses to co-operate with the same error. Yet both of these
approaches work fine for me in a Macro.

How do I write to an arbitrary cell location from a Function?

Thanks.

Bill
  #2   Report Post  
Fredrik Wahlgren
 
Posts: n/a
Default


"Bill Martin -- (Remove NOSPAM from address)"
wrote in message ...
I've got what must be a simple addressing problem but it's driving me
crazy. I can create a simple macro that just looks like:

Sub TestMacro
ActiveCell(1,2) = "Done"
End Sub

And it does exactly what I'd expect. It plugs a value into the cell to
the right of the cursor. Now if I try to do the similar thing with a
Function instead of a Macro it just refuses to co-operate. For example:

Function TestFunct(CellRef)
ActiveCell(1,2) = "Done"
End Function

This will croak with a #VALUE! error. Likewise:

Function TestFunct(CellRef)
CellRef(1,2) = "Done"
End Function

Also refuses to co-operate with the same error. Yet both of these
approaches work fine for me in a Macro.

How do I write to an arbitrary cell location from a Function?

Thanks.

Bill


You can't write to an arbitraty cell from a function. It has to be a Sub.

/Fredrik



  #3   Report Post  
Bob Phillips
 
Posts: n/a
Default

Presumably, you are trying to do this from a worksheet? You can't.

A worksheet function can only return a value, it cannot change any of the
cell or worksheet attributes.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bill Martin -- (Remove NOSPAM from address)"
wrote in message ...
I've got what must be a simple addressing problem but it's driving me
crazy. I can create a simple macro that just looks like:

Sub TestMacro
ActiveCell(1,2) = "Done"
End Sub

And it does exactly what I'd expect. It plugs a value into the cell to
the right of the cursor. Now if I try to do the similar thing with a
Function instead of a Macro it just refuses to co-operate. For example:

Function TestFunct(CellRef)
ActiveCell(1,2) = "Done"
End Function

This will croak with a #VALUE! error. Likewise:

Function TestFunct(CellRef)
CellRef(1,2) = "Done"
End Function

Also refuses to co-operate with the same error. Yet both of these
approaches work fine for me in a Macro.

How do I write to an arbitrary cell location from a Function?

Thanks.

Bill



  #4   Report Post  
Bill Martin -- (Remove NOSPAM from address)
 
Posts: n/a
Default

Fredrik Wahlgren wrote:

You can't write to an arbitraty cell from a function. It has to be a Sub.

/Fredrik

Well, that explains that. Alternatively can I call a Sub from a
Function, and have that Sub write to an arbitrary cell?

Thanks...

Bill
  #5   Report Post  
Bob Phillips
 
Posts: n/a
Default

No, see my reply. The best you can do is use the Worksheet_Change event to
monitor a cell, and if it changes, then trigger your changes.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bill Martin -- (Remove NOSPAM from address)"
wrote in message ...
Fredrik Wahlgren wrote:

You can't write to an arbitraty cell from a function. It has to be a Sub.

/Fredrik

Well, that explains that. Alternatively can I call a Sub from a
Function, and have that Sub write to an arbitrary cell?

Thanks...

Bill





  #6   Report Post  
Bill Martin -- (Remove NOSPAM from address)
 
Posts: n/a
Default

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<html
<head
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"
</head
<body bgcolor="#ffffff" text="#000000"
Bob Phillips wrote:
<blockquote " type="cite"
<pre wrap=""No, see my reply. The best you can do is use the Worksheet_Change event to
monitor a cell, and if it changes, then trigger your changes.

</pre
</blockquote
<font face="Arial"Thanks Bob.&nbsp; I'll have to muddle along some other
how.<br
<br
Bill<br
</font
</body
</html
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
Indexing / Cell Addressing A_n_d_e_r_s Excel Discussion (Misc queries) 1 February 10th 05 11:47 AM
inserting data from a row to a cell, when the row number is specified by a formula in a cell [email protected] New Users to Excel 2 January 6th 05 07:18 AM
Addition to Turn cell red if today is greater or equal to date in cell Rich New Users to Excel 2 December 9th 04 02:06 AM
GET.CELL Biff Excel Worksheet Functions 2 November 24th 04 07:16 PM
VLookup resulting in a blank cell... KempensBoerke Excel Worksheet Functions 1 October 28th 04 09:57 PM


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