Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Nested if returning error 1004

This sub returns error 1004 when it hits the second if statement. Can
you tell me why?

------------
Sub addYears()

Dim year1 As Integer
Dim year2 As Integer

For Each cell In Range("a1", "a3000")
If cell.Value = cell.Offset(1, 0).Value Then
year1 = cell.Offset(0, 4).Value
year2 = cell.Offset(1, 4).Value
cell.Offset(0, 5).Value = year1 + year2
Else
If cell.Value = cell.Offset(-1, 0).Value Then
cell.Offset(0, 5).Value = "See Above"
End If

End If
Next cell
----------

Thanks

-tom


End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Nested if returning error 1004

It works if the second if statement refers to something other than
offset(-1,0), such as offset(1,0), then it works.
Ideas?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Nested if returning error 1004

when your cell is on Row 1 your offset of -1 is an error
Try this:

For Each Cell In Range("a1", "a3000")
If Cell.Value = Cell.Offset(1, 0).Value Then
year1 = Cell.Offset(0, 4).Value
year2 = Cell.Offset(1, 4).Value
Cell.Offset(0, 5).Value = year1 + year2
Else
If Cell.Row 1 Then
If Cell.Value = Cell.Offset(-1, 0).Value Then
Cell.Offset(0, 5).Value = "See Above"
End If
End If
End If
Next Cell


"tom" wrote:

It works if the second if statement refers to something other than
offset(-1,0), such as offset(1,0), then it works.
Ideas?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested If not returning correct values murkaboris Excel Discussion (Misc queries) 5 April 16th 09 06:03 PM
nested IF(OR Vlookup returning zero instead of value in target cel ncjefffl Excel Worksheet Functions 7 October 31st 08 10:20 PM
Nested If statements returning a sum calculation arkage Excel Worksheet Functions 1 April 20th 07 08:59 PM
Nested "if" not returning expected value Michael E W Excel Worksheet Functions 4 September 5th 05 04:50 AM
run-time error '1004': Application-defined or object-deifined error [email protected] Excel Programming 5 August 10th 05 09:39 PM


All times are GMT +1. The time now is 05:46 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"