VBA - Put data in cells

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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)
 
Back
Top