Offset not working with variable

  • Thread starter Thread starter B
  • Start date Start date
B

B

I'm trying to use Offest with a variable as the row offset. When run,
the line does nothing. When I replace the variable with an integer,
it works fine. Heres the code:

' This is where the variable is assigned a value
If InStr(1, UCase(ActiveCell.Offset(0, i).Value), "HOURS") > 0 Then
HoursCol = ActiveCell.Offset(0, i).Column

' It then gets passed to this sub
Public Sub FindWrapperTotals(...HoursCol As Integer, ...)

' Used here:
MsgBox ("HoursCol = " & HoursCol)
HoursNum = ActiveCell.Offset(0, HoursCol - 1).Value
MsgBox ("HoursNum = " & HoursNum)


When run, the first message box says "HoursCol = 8", which is correct,
and the second message box says "HoursNum = ". When I replace
"HoursCol - 1" with an integer, it does exactly what I need...but of
course, life isn't simple enough to always use integers. Thanks in
advance for any advice.
 
How have you declared the variable? If you are passing it between subroutines
then it needs to be public

Public i As Integer

Mike
 
I might need to clarify that in the code I posted, there are two times
where Offset is used with a variable. The variable I'm having trouble
with is "HoursCol." But in response, the variable is public.
 
Turns out it was working, and I had another mistake in my code causing
it to look like it wasnt working.

Silly me.
 

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

Back
Top