Offsetting a varible??

  • Thread starter Thread starter Ashley Milford via OfficeKB.com
  • Start date Start date
A

Ashley Milford via OfficeKB.com

I have this code:

Sub Subtotals()
Dim SubTot As Integer
Dim Line1 As Double

Sheets("Temp").Select
Range("H2").Select
Line1 = Range("L2")
SubTot = Range("P4")
Do Until ActiveCell = ("Condiments")

SubTot = Line1 + SubTot
ActiveCell.Offset(1, 0).Select
Line1 = Range.Offset(1, 0) 'Fails on this line!!!


Range("P4") = SubTot
Loop

Can anyone please help me on being able to step my varible "Line1" down a
row??
 
thank gixxer but both of them say that the line1 in the [] are invaild
qualifiers. the code won't even compile it goes straight to the []'s. also
no i didn't put the [] in the code.

set line1 = [line1].offset(1,0)
line1=[line1].offset(1,0)
 
wait, line1 is dimmed as a double so it can't be modified like that
try dimming line1 as range

Sub Subtotals()
Dim SubTot As Integer
Dim Line1 As Range

Sheets("Temp").Select
Range("H2").Select
set Line1 = Range("L2")
SubTot = Range("P4")
Do Until ActiveCell = ("Condiments")

SubTot = Line1 + SubTot ' may need to do SubTot = Line1.value + SubTot
ActiveCell.Offset(1, 0).Select
set Line1 = Line1.Offset(1, 0)


Range("P4") = SubTot
Loop
 
Hard to know what you are trying to do with Line1, but your problem is the
Use of Range. I have substituted ActiveCell which should work for
eliminating the error, but don't know it is provides the functionality you
want.

Sub Subtotals()
Dim SubTot As Integer
Dim Line1 As Double

Sheets("Temp").Select
Range("H2").Select
Line1 = Range("L2")
SubTot = Range("P4")
Do Until ActiveCell = ("Condiments")

SubTot = Line1 + SubTot
ActiveCell.Offset(1, 0).Select
Line1 = ActiveCell.Offset(1, 0) 'Fails on this line!!!
Range("P4") = SubTot
Loop
 
gixxer,
Tried that, worked but it would not offset the line1 cell. it looped till
the active cell was = to "Condiments" but only added the value of "L2" to
the subtot instead of offsetting it to the row below every loop.

Ashley
 

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