+ Reply to Thread
Results 1 to 3 of 3

Apply Interpolation Formula to Scattered Blank Cells in an Array

  1. #1
    Registered User
    Join Date
    08-05-2021
    Location
    USA
    MS-Off Ver
    365
    Posts
    9

    Apply Interpolation Formula to Scattered Blank Cells in an Array

    Using Office 365.

    I have about 1000 blank cells in an array that I need to fill with an interpolation formula. I believe a Macro would work for this but I' having a hard time figuring out the best way to help the Macro identify the blank cells that need to be filled with the interpolation formula, and once they are identified, how to deal with sequential blank cells (due to the the way the interpolation formula references cells above and below the blank cell to-be-filled). I think the best way to solve this would be to have a Macro locate a blank cell then conduct the interpolation formula with one caveat, the macro would have to set the two cells the formula must reference below the blank cell, to the next available non-blank cells, not simply the cells below the blank cell, regardless of how far down the array they are. I'm grateful for any insight and/or suggestions. Please see below and attached for pictures illustrating the problem and the excel sheet to experiment with.

    Interpolation Macro_Question.png
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    08-05-2021
    Location
    USA
    MS-Off Ver
    365
    Posts
    9

    Re: Apply Interpolation Formula to Scattered Blank Cells in an Array

    Update:

    I made a Macro that achieves my first, less desirable, outcome of cancelling if there are sequential blanks. Looks like this.

    EDIT: Forgot to mention, for "Cells(2,8)" or cell "H2", I have this formula in the excel sheet:
    =IF(MATCH(TRUE,ISBLANK(B1:B1950),0)>0,MATCH(TRUE,ISBLANK(B1:B1950),0),"Done")
    Couldn't get it to work inside the Macro itself. This helps set "y" and ensures the interpolation result in entered into the correct cell.

    Sub auto_interp()

    Dim x As String
    Dim y As Integer

    x = "True"

    While x = "True"
    If Cells(2, 8) > 0 Then x = "True" Else: x = "False"

    y = Cells(2, 8)

    If Cells(y + 1, 2) = 0 Then
    MsgBox "multi blank, terminating"
    x = "False"
    Else: Cells(y, 2) = Cells(y - 1, 2) + ((Cells(y, 1) - Cells(y - 1, 1)) / (Cells(y + 1, 1) - Cells(y - 1, 1)) * (Cells(y + 1, 2) - Cells(y - 1, 2)))
    End If

    Wend
    End Sub

    Maybe another "If" statement to help identify the multi blanks and keep adding 1 to "y", have it try again, if another blank, add another 1 to "y", etc. until it finds a value to use?
    Last edited by udf463; 08-07-2021 at 06:34 PM.

  3. #3
    Registered User
    Join Date
    08-05-2021
    Location
    USA
    MS-Off Ver
    365
    Posts
    9

    Re: Apply Interpolation Formula to Scattered Blank Cells in an Array

    Solved. Added a few more "If" statements that will keep interpolating even if encountering 3 blank cells. At four blank sequential cells, the macro will display a pop up alerting the user off the blank cells and terminating the macro.

    Sub auto_interp()

    Dim x As String
    Dim y As Integer

    x = "True"

    While x = "True"
    If Cells(2, 8) > 0 Then x = "True" Else: x = "False"
    y = Cells(2, 8)

    If Cells(y + 1, 2) > 0 Then
    Cells(y, 2) = Cells(y - 1, 2) + ((Cells(y, 1) - Cells(y - 1, 1)) / (Cells(y + 1, 1) - Cells(y - 1, 1)) * (Cells(y + 1, 2) - Cells(y - 1, 2)))
    Else:
    If Cells(y + 1, 2) = 0 Then
    If Cells(y + 2, 2) > 0 Then Cells(y, 2) = Cells(y - 1, 2) + ((Cells(y, 1) - Cells(y - 1, 1)) / (Cells(y + 2, 1) - Cells(y - 1, 1)) * (Cells(y + 2, 2) - Cells(y - 1, 2)))
    If Cells(y + 2, 2) = 0 Then
    If Cells(y + 3, 2) > 0 Then Cells(y, 2) = Cells(y - 1, 2) + ((Cells(y, 1) - Cells(y - 1, 1)) / (Cells(y + 3, 1) - Cells(y - 1, 1)) * (Cells(y + 3, 2) - Cells(y - 1, 2)))
    If Cells(y + 3, 2) = 0 Then
    MsgBox "Four Blank Cells Encountered, Terminating Macro"
    x = "False"

    End If
    End If
    End If
    End If
    Wend

    End Sub

+ 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. [SOLVED] Array Formula which ignores blank cells / only calculates cells with values
    By LordByron in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 08-02-2020, 06:47 AM
  2. Need to make a formula to average a scattered cells to the right of LABELS
    By Manahotep in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-10-2015, 01:58 PM
  3. [SOLVED] VBA Apply Formula to Non Blank Cells in Range
    By hobbiton73 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-02-2014, 11:58 AM
  4. [SOLVED] Macro to apply formula to blank cells in a column is offset (sometimes)
    By Chrispelletier in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-07-2013, 01:55 PM
  5. [SOLVED] Array formula to ignore blank cells
    By trickeyja in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-22-2012, 07:35 PM
  6. Bilinear interpolation of scattered data points
    By Sebi in forum Excel General
    Replies: 15
    Last Post: 09-19-2012, 01:05 AM
  7. Skipping Blank cells in formula(searched but cant figure how to apply)
    By scotinexcile in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 08-21-2012, 09:14 PM

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