• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member
  • Login

Extrapolate from a table of values|General Excel Questions & Answers|Excel Forum|My Online Training Hub

You are here: Home / Extrapolate from a table of values|General Excel Questions & Answers|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumGeneral Excel Questions & Answe…Extrapolate from a table of values
sp_PrintTopic sp_TopicIcon
Extrapolate from a table of values
Avatar
Robert Green
Member
Members
Level 0
Forum Posts: 25
Member Since:
November 9, 2020
sp_UserOfflineSmall Offline
1
June 13, 2023 - 3:31 am
sp_Permalink sp_Print

I have some data on company sizes and want to chart this and extrapolate to find say, the number of companies with 100 employees, or 200 employees, or 1000 employees etc.

Number of employees Number of companies
1 - 9 1,187,045
10 - 49 217,240
50 - 249 35,940
250+ 7,675

or even to extend the table to the first column is in smaller buckets.

Again, any help appreciated. Thanks

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1844
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
June 15, 2023 - 4:46 pm
sp_Permalink sp_Print

Hi Robert,

Here is a UDF function for linear interpolation I created a while ago:

Option Explicit
Function Interpolate(Y As Double, Tbl As Range, _
RdColData As Long, Optional VerticalTable As Boolean = True)
Dim HorizontalTable As Label
'Catalin Bombea - Iasi, 2013

'first argument - TargetVal As Double is the reference value

'second argument - Tbl As Range,, is the data range;

'the third argument - RdColData As Integer, represents the column number of the data range, from this column the function will extract values.
'(must be set to Long instead of integer, for large tables of data)
'If you want to return results from second column, set this argument to 2.
'in horizontal tables, if you want to return data from 3'rd row, set this argument to 3.
'This argument can be 1, but because the function will always look for the reference value in first column for vertical data tables,
'or in first row for horizontal data tables, it will return the same data type as the reference value

'last argument-Optional VerticalTable As Boolean = True : "TRUE or FALSE. We should use TRUE (this argument is optional, the default value is TRUE)
'for vertical tables, if we have data in 2 or more columns;
'If the table is horizontal, (with data in 2 or more rows, but several columns of data), FALSE value must be used.
'IF FALSE is used, then the numeric argument will represent the ROW number to return values from, instead of COLUMN number).
'IMPORTANT:
'If this argument is TRUE, the function will look in the first COLUMN of the data range to find the reference value,
'and it will return values from one of the next columns, based on the value of the third argument; if this argument is FALSE,
'the function will search the reference value in the first ROW of the data table, and it will return values from one of the next rows,
'based on the value of the third argument."

Application.Volatile
Application.ScreenUpdating = False

Dim Y1 As Double, Y2 As Double, X1 As Double, X2 As Double, i As Long

If VerticalTable = False Then GoTo HorizontalTable
'when the loop ends, the next item is Y2, the closest higher value from data table
For i = 1 To Tbl.Rows.Count
If IsNumeric(Tbl.Cells(i, 1)) And Tbl.Cells(i, 1) > Y Then
Exit For
End If
Next i

Y1 = Tbl.Cells(i - 1, 1)
Y2 = Tbl.Cells(i, 1)
X1 = Tbl.Cells(i - 1, RdColData)
X2 = Tbl.Cells(i, RdColData)

Interpolate = X1 + (X2 - X1) * (Y - Y1) / (Y2 - Y1)
Application.ScreenUpdating = True
Exit Function

HorizontalTable:

For i = 1 To Tbl.Columns.Count
'when the loop ends, the next item is Y2, the closest higher value from data table
If IsNumeric(Tbl.Cells(1, i)) And Tbl.Cells(1, i) > Y Then
Exit For
End If
Next i

Y1 = Tbl.Cells(1, i - 1)
Y2 = Tbl.Cells(1, i)
X1 = Tbl.Cells(RdColData, i - 1)
X2 = Tbl.Cells(RdColData, i)

Interpolate = X1 + (X2 - X1) * (Y - Y1) / (Y2 - Y1)
Application.ScreenUpdating = True
End Function

To use it, you should change your table to set the max limits instead of ranges:

Number of employees                                       Number of companies

9 1187045
49 217240
249 35940
250 7675

To use it in sheet:

=IF(D2>=250,XLOOKUP(250,SampleData[Number of employees],SampleData[Number of companies],0),Interpolate(D2,SampleData,2,TRUE))

I'm attaching a more detailed file with your sample and other explanations, from <a href="https://www.excel-first.com/user-defined-function-for-linear-interpolation-in-excel/">this source</a>

image_2023-06-15_094233617.pngImage Enlarger

sp_PlupAttachments Attachments
  • sp_PlupImage image_2023-06-15_094233617.png (31 KB)
sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Susan VanRiper, Sue Hammond, Tracy English, David Panthol, Mohamed Touahria
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 880
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 237
Jessica Stewart: 219
A.Maurizio: 213
Aye Mu: 201
jaryszek: 183
Newest Members:
David von Kleek
Ronald White
Ginette Guevremont
Taryn Ambrosi
Mark Davenport
Christy Nichols
Harald Endres
Ashley Hughes
Herbie Key
Trevor Pindling
Forum Stats:
Groups: 3
Forums: 24
Topics: 6528
Posts: 28594

 

Member Stats:
Guest Posters: 49
Members: 32817
Moderators: 2
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel Office Scripts
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook

Sign up to our newsletter and join over 400,000
others who learn Excel and Power BI with us.

 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate
  • Sponsor Our Newsletter

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.