+ Reply to Thread
Results 1 to 2 of 2

Application/Object Defined Error when moving to 'Else Statement'

  1. #1
    Registered User
    Join Date
    01-19-2017
    Location
    Milwaukee, WI
    MS-Off Ver
    2010
    Posts
    6

    Application/Object Defined Error when moving to 'Else Statement'

    Hi everyone,

    I've written some lines of code to enter formulas in different cells depending on the value of a column's cells. Everything goes smoothly up until I hit the 'else statement'. What is weird is that the 'else statement' is virtually identical to the 'if statement', just using different cell references. Can anybody help me think through this? I'm at a loss for what the issue is (any other tips would be appreciated too). Here's the code:


    Dim LastRow As Long
    LastRow = Worksheets("Item Details").Range("D1").CurrentRegion.Rows.Count
    ' ^Identifies the last row in the worksheet and assigns to variable "LastRow"

    Dim Rng As Range
    Dim Cell As Range
    Set Rng = Range(Cells(2, 24), Cells(LastRow, 24))
    ' ^Assigns the range of X2 down to the last row in column X to the variable "Rng"

    Range("x2").Select
    Dim x As Integer

    For x = 2 To LastRow
    If ActiveCell.Value = "CY-" Then
    ActiveCell.Offset(0, 8).Formula = ActiveCell.Offset(0, 17).Value & ActiveCell.Offset(0, -10).Value
    ActiveCell.Offset(0, 9).Formula = ActiveCell.Offset(0, 18).Value & ActiveCell.Offset(0, -10).Value
    ActiveCell.Offset(0, 10).Formula = ActiveCell.Offset(0, 19).Value & ActiveCell.Offset(0, -10).Value
    ActiveCell.Offset(0, 11).Formula = ActiveCell.Offset(0, 17).Value & ActiveCell.Offset(0, -8).Value
    ActiveCell.Offset(0, 12).Formula = ActiveCell.Offset(0, 18).Value & ActiveCell.Offset(0, -8).Value
    ActiveCell.Offset(0, 13).Formula = ActiveCell.Offset(0, 19).Value & ActiveCell.Offset(0, -8).Value
    ActiveCell.Offset(0, 14).Formula = ActiveCell.Offset(0, 17).Value & ActiveCell.Offset(0, -9).Value
    ActiveCell.Offset(0, 15).Formula = ActiveCell.Offset(0, 18).Value & ActiveCell.Offset(0, -9).Value
    ActiveCell.Offset(0, 16).Formula = ActiveCell.Offset(0, 19).Value & ActiveCell.Offset(0, -9).Value

    ActiveCell.Offset(1, 0).Select
    Else <--------------------------------------------------------------------------------------------------------------------------------Error given when moving to 'else'
    ActiveCell.Offset(0, 5).Formula = ActiveCell.Offset(0, 3).Value & ActiveCell.Offset(-10).Value
    ActiveCell.Offset(0, 6).Formula = ActiveCell.Offset(0, 3).Value & ActiveCell.Offset(-8).Value
    ActiveCell.Offset(0, 7).Formula = ActiveCell.Offset(0, 3).Value & ActiveCell.Offset(-9).Value

    ActiveCell.Offset(1, 0).Select
    End If
    Next







    Thanks!

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Application/Object Defined Error when moving to 'Else Statement'

    Unfortunately your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 08-19-2015, 07:10 PM
  2. VBA ERROR: run time error 1004: Application-defined or Object-defined error in excel 2013
    By AnanthKrishna in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-13-2015, 06:16 AM
  3. excel macro run time error '1004'- Application defined or object defined error
    By kmadan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-16-2014, 09:51 AM
  4. Replies: 1
    Last Post: 03-12-2014, 12:42 PM
  5. [SOLVED] Run time error 1004 Application-Defined or Object-Defined Error - Placing data into next e
    By michelle 1 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-27-2014, 12:57 PM
  6. [SOLVED] run-time error '1004' application-defined or object-defined error - Excel 2007
    By kaurka in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2012, 02:46 AM
  7. Replies: 2
    Last Post: 09-12-2012, 01:01 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1