Writing value to worksheet cell

G

Guest

This sub causes a #Value error to reflect in the cell. It kicks out when I
am trying to write some info to a separate sheet (for verification purposes).
When Excel hits the line where it write to the DebugIt sheet, Excel stops
processing the calling cell and goes to the next one.

As a test, I placed info into the cell (where it is suppose to write the
info) and that info is placed into vTemp on that line, but I can't get it to
write strTemp into that cell (the cell is not locked). The commented out
lines is where I tried to use the .cells property of Worksheets instead of
range - does the same thing.

nRow = 221, nTempRow = 1, and nEmployed = 0

Public Sub WriteData(nRow As Integer, nTempRow As Integer, nEmployed As
Integer)
Dim vRow As Variant, strTemp As String, vTemp As Variant

With Worksheets("DebugIt")
vRow = "A" + CStr(nTempRow) ' Put col A w/nTempRow into vRow
strTemp = "A" + CStr(nRow) ' Put source as "A" with row into var to
write into DebugIt sheet cell
' .Cells(nTempRow, 1).Value = strTemp
' .Cells(nTempRow, 2).Value = 0
vTemp = .Range(vRow).Value
.Range(vRow).Value = strTemp ' Write var into DebugIt sheet
vRow = "B" + CStr(nTempRow) ' change to "B" Col
vTemp = .Range(vRow).Value
.Range(vRow).Value = nEmployed ' write into DebugIt sheet
End With

End Sub

John H W
 
J

John Green

If you are trying to execute this sub from a user defined function
referenced in a worksheet cell calculation, it will not work. UDFs are not
permitted to change the worksheet (apart from returning a value to the
calculation). It could write the value to the debug window or an external
file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top