Results 1 to 3 of 3

Question Inserting Rows based on cell differences and interpolating in between

Threaded View

  1. #1
    Registered User
    Join Date
    07-04-2011
    Location
    Cairo
    MS-Off Ver
    Excel 2010
    Posts
    3

    Question Question Inserting Rows based on cell differences and interpolating in between

    Hello -

    I have a complicated issue. I have a file with 5 columns (A, B, C, D, E).
    A is fixed string value.
    B is a number increasing irregularly.
    C, D, E, are given values.

    What I need to do is have column B regular (i.e. every 1). So I have to insert rows between B i.e.(B2-B1) will determine how many rows between B1 & B2 and then (B3-B2) will determine how many rows between B2 & B3 and so on.
    After inserting the rows, I have to linear interpolate columns C, D & E in the newly created empty rows. In all cases I want to keep the original values and interpolate between them.

    The other issue is that column B has decimal/fraction, but I think I can round this to the nearest integer to make it easier for interpolation.

    I tried this one but I think I have a problem with the insert loop!

    Option Explicit
    Sub Test01()
    Application.ScreenUpdating = False
    Dim numRows As Long
    Dim r As Long
    Dim Rng As Range
    Dim lastrw As Long
    Dim Ar As Range
    Dim StepValue1
    Dim StepValue2
    Dim StepValue3
    Dim Ar1 As Range
    Dim AR2 As Range
    
    Dim i As Integer
    lastrw = Cells(Rows.Count, "A").End(xlUp).Row
       
        i = 1
        For i = i + 0 To lastrw Step 1
            
        Set Rng = Range(Cells(i, "A"), Cells(lastrw, "A"))
        numRows = Cells(i + 1, 2).Value - Cells(i + 0, 2).Value
            
            For r = Rng.Rows.Count To 1 Step -1
            Rng.Rows(r + i).Resize(numRows - 1).EntireRow.Insert
            Next r
        Next i
          
    Set Rng = Columns(1).SpecialCells(xlBlanks)
    For Each Ar In Rng.Areas
    Set Ar1 = Ar.Offset(-1, 0).Resize(Ar.Rows.Count + 1)
    Set AR2 = Ar1.Resize(Ar1.Rows.Count + 1)
    
    StepValue1 = (AR2(AR2.Count).Offset(0, 2) - _
    Ar1(1).Offset(0, 2)) / Ar1.Count
    
    StepValue2 = (AR2(AR2.Count).Offset(0, 3) - _
    Ar1(1).Offset(0, 3)) / Ar1.Count
    
    StepValue3 = (AR2(AR2.Count).Offset(0, 4) - _
    Ar1(1).Offset(0, 4)) / Ar1.Count
    
    Ar1.Offset(0, 2).DataSeries Rowcol:=xlColumns, _
    Type:=xlLinear, Date:=xlDay, _
    Step:=StepValue1, Trend:=False
    
    Ar1.Offset(0, 3).DataSeries Rowcol:=xlColumns, _
    Type:=xlLinear, Date:=xlDay, _
    Step:=StepValue2, Trend:=False
    
    Ar1.Offset(0, 4).DataSeries Rowcol:=xlColumns, _
    Type:=xlLinear, Date:=xlDay, _
    Step:=StepValue3, Trend:=False
    
    Next
    
    End Sub
    Example Input: http://i65.tinypic.com/v30kz6.jpg
    Desired output: http://i66.tinypic.com/2hrod4n.jpg
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. inserting rows based on cell range not being blanks
    By benoj2005 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-23-2014, 08:33 AM
  2. Inserting Rows Based on Cell Value.
    By feather-chaser in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-12-2014, 05:39 AM
  3. [SOLVED] Splitting cell contents based on Comma and inserting new rows below it.
    By SS113 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-22-2013, 09:09 AM
  4. Inserting Rows based on a cell value and populating them.
    By Cleanroomservices in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-22-2012, 11:24 AM
  5. Inserting, Cutting, and Pasting Rows Based on What's in a Cell
    By 4EverLearning in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-05-2010, 04:42 PM
  6. Inserting rows based on cell value
    By iwontbelost in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-17-2009, 07:45 AM
  7. Inserting Rows w/formulas question
    By Buckwheat in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-07-2005, 06:06 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