Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Function -- trouble writing to ActiveSheet

Status
Not open for further replies.

lancish

Technical User
Aug 2, 2004
1
0
0
US
I am writing my first major VBA function after writing many small ones. It's a big retirement program that updates a retirement fund monthly and runs for, like, 50 years. Every year, I want to print to the active worksheet the accumulated results for expenditures, income, change in fund, etc., writing 13 variables on one line. I debug the program by stepping it through and watching the "local" variables take/change, and I know they have the correct value. But, when I try to write to the active sheet, it writes the first cell (roww, 5) but bombs out on trying the second write. Here's a slice of the code, where
roww is Dim as integer and computed,
k is Dim as integer and is the year-counter,
StartYear for debugging is Dim as integer, and
cum_work_income is Dim as Currency, and I see it has the correct value:

Cells(roww, 5).Value = StartYear + k
Cells(roww, 6).Value = cum_work_income
Cells(roww, 7).Value = cum_ret_income
Cells(roww, 8).Value = cum_addl_income

Any thoughts would be deeply appreciated!!

Thanks, Lancish

 
but bombs out
Any error message ?
Anyway, a row counter should be dimmed As Long.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
In the absence of an error message....

Try checking that the worksheet and the range you are writing to i.e. Cells(roww, 5) isn't protected.

Hope this helps, Le
 
Excel needs you to qualify which sheet you want to use. You need to use something like:

With Activesheet
.Cells(roww, 5).Value = StartYear + k
.Cells(roww, 6).Value = cum_work_income
.Cells(roww, 7).Value = cum_ret_income
.Cells(roww, 8).Value = cum_addl_income
'etc etc
end with

Rgds, Geoff

Never test the depth of water with both feet

Help us to help you by reading FAQ222-2244 before you ask a question
 
Just a thought if you haven't found the problem yet.

Check that none of the cells have been merged prior to making the data transfer



Merry Part and the Brightest of Blessings

With respect
Wicca
-----
IF you think you can
Or
If you think you can't
Then
You are probably right
-Henry Ford
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top