Help with code

The Idea Dude

Well-known Member
Joined
Aug 15, 2002
Messages
589
I thought I did a good job conjuring this up, lol, appears that some syntax is still wrong........any pointers :)

Thanks :)

Code:
Sub eighteenawake()

    Dim c As Range
    
    For Each c In Worksheets("Sheet2").Range("I2:I49").Cells
        If c.Value - c.Offset(-4, 0).Value = c.Value - 2 Then Range("N7").Value = c.Offset(-36 + (c.Offset(-5, 0).Value * 2), -2).Value
    Next

End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

SteveO59L

Well-known Member
Joined
Apr 21, 2004
Messages
7,896
Doesnt the first argument in an offset statement refer to the row ?.

If it does, and you start at I2, you cant offset by -4 rows.
 

The Idea Dude

Well-known Member
Joined
Aug 15, 2002
Messages
589
Yeah....ooops.....was going minus for down rows. Have adjusted but it is still giving me an error from the then statement.

Code:
Sub eighteenawake()

    Dim c As Range
    
    For Each c In Worksheets("Sheet2").Range("I2:I49").Cells
        If c.Value - c.Offset(4, 0).Value = c.Value - 2 Then Range("N7").Value = c.Offset(36 + (c.Offset(5, 0).Value * 2), -2).Value
    Next
End Sub
 

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
Hi
Code:
Range("N7").Value = c.Offset(36 + (c.Offset(5, 0).Value * 2), -2).Value
what are you tryign to do with this line and what value in c.Offset(5,0)?

anyway tyr
Code:
Sheets("Sheet2").Range("N7").Value=c.Offset(36+(c.offset(5,0).value * 2),-2).value
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707

ADVERTISEMENT

Hi

Is Sheet2 the activesheet when you run the code? If not, precede the Range("N7") etc after the Then with Sheets("Sheet2").

Richard
 

The Idea Dude

Well-known Member
Joined
Aug 15, 2002
Messages
589
Yes sheet 2 is the active sheet :)

The value in c.Offset(5, 0) is just a number

The code is stopping at Sheets("Sheet2")...

Code:
Sub eighteenawake()

    Dim c As Range
    
    For Each c In Worksheets("Sheet2").Range("I2:I49").Cells
        If c.Value - c.Offset(4, 0).Value = c.Value - 2 Then Sheets("Sheet2").Range("N7").Value = c.Offset(36 + (c.Offset(5, 0).Value * 2), -2).Value
    Next
End Sub
 

The Idea Dude

Well-known Member
Joined
Aug 15, 2002
Messages
589
Geepers......another bit of code had pw protected the sheet...got it sorted...cheers for the help :)
 

Forum statistics

Threads
1,141,222
Messages
5,705,109
Members
421,378
Latest member
CarlosDuran

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top