+ Reply to Thread
Results 1 to 3 of 3

Create a Formula from Set Variables as ActiveCell

  1. #1
    Registered User
    Join Date
    03-17-2015
    Location
    Los Angeles, USA
    MS-Off Ver
    2010
    Posts
    3

    Create a Formula from Set Variables as ActiveCell

    Trying to write a formula inserting rows based on the difference between the ActiveCell and a cell above it, if the cell above is larger. The entire code works, except for the formula for "Diff". If I replace diff with a number, ie. "2", then the formula works fine. However the number of inserted rows need to vary based on the difference between the ActiveCell and the one above it. I even based the formula on non-explicit variables (IND, and INDabove) but the formula just keeps crashing on one specific line: ActiveCell.Resize(Diff).EntireRow.Insert

    Below is my code...


    Sub Indentured()

    ' Indentured Macro
    ' Keyboard Shortcut: Ctrl+W

    Dim LR As Long
    Dim IND As Range
    Dim INDabove As Range
    Dim Diff As Long
    Application.ScreenUpdating = False

    LR = Range("E" & Rows.Count).End(xlUp).Row
    Set IND = ActiveCell
    Set INDabove = ActiveCell.Offset(-1, 0)
    Diff = ActiveCell.Offset(-1, 0).Value - ActiveCell.Value - 1

    Range("E" & LR).Select
    Do Until ActiveCell.Row = 2
    If ActiveCell.Value < ActiveCell.Offset(-1, 0).Value Then
    ActiveCell.Resize(Diff).EntireRow.Insert
    End If
    ActiveCell.Offset(-1).Select
    Loop
    Application.ScreenUpdating = True
    End Sub
    Last edited by lreyes; 03-18-2015 at 01:40 AM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Re: Create a Formula from Set Variables as ActiveCell

    Looking at the code, you have "Diff" before the loop. It needs to be part of the loop.

  3. #3
    Registered User
    Join Date
    03-17-2015
    Location
    Los Angeles, USA
    MS-Off Ver
    2010
    Posts
    3

    Re: Create a Formula from Set Variables as ActiveCell

    That worked!! You are a genius!!

+ 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. Selecting Activecell and cell next to the Activecell
    By Raghukumarn in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-31-2013, 06:32 AM
  2. [SOLVED] Activecell.formula vba
    By DeNam in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-31-2013, 06:46 AM
  3. [SOLVED] create a formula that covers several variables/possabilities
    By clovelly in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 01-31-2013, 07:35 AM
  4. Output contents of Activecell when Activecell may be string or numeric.
    By jfriddle in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2012, 12:27 PM
  5. CREATE NEW WORKBOOKS BASED ON ACTIVECELL & BUTTON CLICK
    By Eddy Stan in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-01-2006, 01:35 AM

Tags for this Thread

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