![]() |
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 |
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 |
All times are GMT +1. The time now is 04:19 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com