Unable to view variable

K

KevinM

I'm unable to get the value stored in the variable. I'm not sure what I'm
doing wrong. I get a value of zero. Here's what I'm doing to check the
value of the data:

Sub SetVarFromCell()
Dim paycode12 As Long


MsgBox (ThisWorkbook.Name & " " & ActiveSheet.Name & " " &
ActiveCell.Address)
MsgBox (ActiveCell.Value)
paycode12 = Worksheets("flx00012.tmp").Cells(18, "L").Value
MsgBox (paycode12)


End Sub


Any help is appreciated.
 
J

john

I placed value of 10 in cell L18 and your variable returned 10. So begs the
question, have you got a value > 0 in cell L18 in specified worksheet?
 
J

Joel

You may have more than one workbook opened. See if this helps

Sub SetVarFromCell()
Dim paycode12 As Long


MsgBox (ThisWorkbook.Name & " " & ActiveSheet.Name & " " &
ActiveCell.Address)
MsgBox (ActiveCell.Value)
with Thisworkbook
paycode12 = .Worksheets("flx00012.tmp").Cells(18, "L").Value
end with
MsgBox (paycode12)


End Sub
 
K

KevinM

Thanks Joel. I still get a zero value. Let me back up a bit. Here is the
code I'm using that's using variable "paycode12". I get no error when I run
it but its not giving me the value stored in these variables. If you can
assist me on getting the value out of these variables. I really appreciate
the help. Thanks in advance.


Sub retropay2()

Dim paycode12 As Long
Dim paycode13 As Integer
Dim paycode1E As Integer
Dim paycode1H As Integer
Dim paycode1I As Integer
Dim paycode1J As Integer
Dim paycode1 As Integer
Worksheets("flx00012.tmp").Activate
finalrow1 = Cells(65536, 6).End(xlUp).Row
For j = 1 To finalrow1

'this will see if j,6 is equal to paycode 1,12,13
Select Case Cells(j, 6).Value
Case 1
paycode1=Cells(j, 12).Formula = Cells(j, 7) * Cells(j, 11)
Case 12
paycode12 = Cells(j, 12).Formula = Cells(j, 7) * Cells(j, 11)

Case 13
paycode13 = Cells(j, 12).Formula = Cells(j, 7) * Cells(j, 11)

'this will look at paycode 1E 1H in j,6
Case "1E"
paycode1E = Cells(j, 12).Formula = Cells(j, 7) * Cells(j, 11)
Case "1H"
payrcode1H = Cells(j, 12).Formula = Cells(j, 7) * Cells(j, 11)

End Select
Next j
End Sub
 
K

KevinM

Yes, the value is greater than zero. Thank you.
john said:
I placed value of 10 in cell L18 and your variable returned 10. So begs the
question, have you got a value > 0 in cell L18 in specified worksheet?
 
J

Joel

These changes should work

Sub retropay2()

Dim paycode12 As Long
Dim paycode13 As Integer
Dim paycode1E As Integer
Dim paycode1H As Integer
Dim paycode1I As Integer
Dim paycode1J As Integer
Dim paycode1 As Integer
Dim finalrow1 As Long
With Worksheets("flx00012.tmp")
finalrow1 = .Cells(65536, 6).End(xlUp).Row
For j = 1 To finalrow1

'this will see if j,6 is equal to paycode 1,12,13
Select Case .Cells(j, 6).Value

Case 1
paycode1 = .Cells(j, 7) * .Cells(j, 11)
.Cells(j, 12) = paycode1
Case 12
paycode12 = .Cells(j, 7) * .Cells(j, 11)
.Cells(j, 12) = paycode12
Case 13
paycode13 = .Cells(j, 7) * .Cells(j, 11)
.Cells(j, 12) = paycode13

'this will look at paycode 1E 1H in j,6
Case "1E"
paycode1E = .Cells(j, 7) * .Cells(j, 11)
.Cells(j, 12) = paycode1E
Case "1H"
payrcode1H = .Cells(j, 7) * .Cells(j, 11)
.Cells(j, 12) = payrcode1H

End Select
Next j
End With
End Sub
 

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