Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA - Put data in cells

I have a vba function as follows:

Function zputData()
Dim cell As Range

Set Range1 = ActiveSheet.Range("a1:a7")
For Each cell In Range1.Cells
cell.Value = "abc"
Next
End Function

If i put =zputData() in A10 I get a #VALUE! and do not get abc in cells a1 to a7.

If i execute abc= zputData() in the immediate window, a1 to a7 gets set.

What am I doing wrong?

Thanks,
Fred


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default VBA - Put data in cells

Fred,

A function called from within a worksheet can only return a result, it
cannot change the attributes of cells, especially other cells.

You can't do what you are trying to do. The best you could do would be to
have event code that does it based upon a condition.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"fredz" wrote in message
...
I have a vba function as follows:

Function zputData()
Dim cell As Range

Set Range1 = ActiveSheet.Range("a1:a7")
For Each cell In Range1.Cells
cell.Value = "abc"
Next
End Function

If i put =zputData() in A10 I get a #VALUE! and do not get abc in cells a1

to a7.

If i execute abc= zputData() in the immediate window, a1 to a7 gets set.

What am I doing wrong?

Thanks,
Fred




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
compare 2 column cells and return the adjacent columns cells data of the cell trebor57 Excel Worksheet Functions 1 February 1st 11 02:54 PM
join data in multiple cells when adjoining cells match criteria ?? angiec50 Excel Worksheet Functions 1 October 6th 09 10:27 AM
Need to average data if in cells, but ignore blank cells. Paula Excel Worksheet Functions 4 July 1st 09 05:38 PM
Returning data of multiple cells for lookup of mulltiple cells HELP on data reference formulas Excel Discussion (Misc queries) 1 October 29th 08 08:27 PM
trying to create an (almost) circular formula between cells and data validated cells with lists KR Excel Worksheet Functions 0 May 12th 05 07:21 PM


All times are GMT +1. The time now is 06:07 PM.

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"