Help with code

The Idea Dude

Well-known Member
Joined
Aug 15, 2002
Messages
591
Office Version
  1. 2016
Platform
  1. Windows
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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
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.
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
Hi

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

Richard
 
Upvote 0
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
 
Upvote 0
Geepers......another bit of code had pw protected the sheet...got it sorted...cheers for the help :)
 
Upvote 0

Forum statistics

Threads
1,214,913
Messages
6,122,207
Members
449,074
Latest member
cancansova

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
Back
Top