increment by input message box and interpolate between removed data

Brandon M

Board Regular
Joined
Sep 18, 2015
Messages
66
I am trying to write a code that will take column B and increment the values in the column by a value that can be entered into an input message box by the user. In the example provided below the user wants 0.1 as his or her increment for column B. Column A should be linearly interpolated as column B is shortened.
So far my code is just set up to grab data from the specified machine and bring it into the sheet where the raw data will be cleaned into usable data. I’ve been researching for days and can’t quite get my head around how to set the increment and interpolate the data.

Raw data looks similar to this but much larger. There is a lot of data missing here. One of the files has nearly 13000 rows. A completely parsed file will have less than 400 rows.
A B
0.000.01
0.000.01
0.000.01
0.000.01
0.000.01
0.000.02
0.000.02
0.000.02
0.000.03
0.170.03
0.170.03
0.170.04
0.340.04
0.170.05
0.170.05
0.340.06
0.340.07
0.510.07
0.510.07
0.510.08
0.680.09
0.680.10
0.680.10
0.840.11
0.840.12
0.840.12

<tbody>
</tbody>


Cleaned data should look something like this:
A B
0.10.527421817
0.20.991580884
0.31.586479186
0.42.314630901
0.52.835397098
0.63.544292655
0.74.022441664
0.84.613159911
0.95.105284463
15.593649288
1.16.14812775
1.26.687576899
1.37.186948527
1.47.721394663
1.58.216697024
1.68.832567724
1.79.419757746
1.810.02798463
1.910.64584242
211.2516133
2.111.91266204
2.212.51039649
2.313.09953086
2.413.64477697
2.514.36453506
2.615.08429885
2.715.67496777
2.816.29622629
2.916.91370968
317.60455092
3.118.17145856

<tbody>
</tbody>


My code so far. This is basically just moving files from the file location to the target sheet and creating new tabs, naming tabs, etc. Some of the dims are not used yet as I’ve just been trying different things to make my code work.

Code:
Sub interpolate()
 
Dim i As Integer    'counter for raw data row count
Dim j As Integer    'counter for clean data column count
Dim k As Integer    'counter for raw data column count
Dim count As Integer
 
Dim Load(1 To 20000) As Variant
Dim Disp(1 To 20000) As Variant
Dim z1(1 To 20000) As Variant
Dim r
 
Dim DataFile As String
Dim DataName As String
Dim DataSheetName As String
Dim Message As String
Dim Title As String
Dim Default As String
Dim DataSheetVariant As Variant
Dim DataSheetNumber As Integer
Dim ProgramName As String
Dim WBf As Workbook
Dim WBt As Workbook
Dim DSA As Worksheet 'DSA=Data Set A
Dim fnameandpath As Variant
Dim path As String, filename As String, filetype As String
Dim SpacePos As Integer
Dim SV As Integer   'SV=Serial number Search Value
Dim Inc As Double  'deflection increment value
 
'**************TEST DATA LOCATION******************
ChDrive "U:\"
ChDir "U:\location"
fnameandpath = Application.GetOpenFilename()
If fnameandpath = False Then Exit Sub
'*************************************************
 
 
Set WBf = Workbooks.Open(fnameandpath)
Set WBt = ThisWorkbook
'Set RD = WBt.Sheets.Add(After:=Sheets(WBt.Sheets.Count))
 
'On Error GoTo User_Canceled:
 
'***************************
'Enter desired serial number and find in from file
'***************************
SV = InputBox("Please provide serial number.", "Serial Number")
'If SV = "" Then Exit Sub
Set found = Range("A1:FZ1").Find(What:=SV, LookIn:=xlValues, LookAt:=xlWhole)
If found Is Nothing Then
    MsgBox "Serial number not found."
    Else
    'selects 4 columns and 16000 rows from serial number designation
    found.Offset(0, 0).Resize(16000, 2).Copy
    found.Offset(1, 0).Select
End If
 
'************************
'Copy Data from file
'************************
 
'With WBf
'Sheets("Raw Data").Select
'Range(Cells(1, 1), Cells(15000, 65)).Select
'Selection.Copy
'End With
 
'*********************
'return to target worksheet
'*********************
WBt.Activate
'create new worksheet
Set DSA = WBt.Sheets.Add(after:=WBt.Sheets(ThisWorkbook.Sheets.count))
DSA.Name = "Data Set A"
 
With WBt
ary = Split(fnameandpath, "\")
bry = Split(ary(UBound(ary)), ".")
ary(UBound(ary)) = ""
path = Join(ary, "\")
filename = bry(0)
filetype = bry(1)
 
End With
 
'*********************************
'Copying file name to new tab name
'*********************************
With RD
Range("A1") = "Path:"
Range("A2") = "Filename:"
'Range("A3") = "Filetype:"
 
Range("B1") = path
Range("B2") = filename
'Range("B3") = filetype
 
SpacePos = InStr(Range("B2"), " ")  'Looks for space in string
 
ActiveSheet.Name = Left(Range("B2"), SpacePos + 0) 'use everything to the left of the space and 14 char to the right
 
'***********************
'Paste Data into new Tab
'***********************
Range("A4").PasteSpecial xlPasteAll
End With
 
Application.DisplayAlerts = False
WBf.Close False
 
‘This is just my first attempts at figuring out a way to get the increment working. It’s all wrong.
'Inc = InputBox("Please specify deflection increment value.")
Range("B7") = ActiveCell
i = 7
j = 7
i = i + 1
test = (ActiveCell.Value) - ActiveCell.Offset(1, 0).Value < 0.001
Do While ActiveCell <> ""
If test = True Then
    ActiveCell.Offset(1, 0).EntireRow.Delete
Else
    ActiveCell.Offset(1, 0).Select
End If
Loop
'Do While ActiveCell <> ""
'User_Canceled:
End Sub

Thanks in advance for any help. All suggestions are much appreciated.

Best,
Brandon
 
Last edited:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Lots of views and no replies. Is this because my question is too complex or because no one understands what I'm asking?
 
Upvote 0
Lots of views and no replies. Is this because my question is too complex or because no one understands what I'm asking?

i won't say i don't understand what you are asking, just that i am confused by your examples and i can not see any logic to what you ask and what you show

i see that you are creating a list in column that increments by a value of 0.1 but where do we get the 0.527421817 from and how does the maths work to make this 0.991580884 in the next

maybe a little more explanation one example at a time and telling us your logic in plain words rather on relying on the examples (which mean something to you but not me, but may upon further detail)
 
Upvote 0
i won't say i don't understand what you are asking, just that i am confused by your examples and i can not see any logic to what you ask and what you show

i see that you are creating a list in column that increments by a value of 0.1 but where do we get the 0.527421817 from and how does the maths work to make this 0.991580884 in the next

maybe a little more explanation one example at a time and telling us your logic in plain words rather on relying on the examples (which mean something to you but not me, but may upon further detail)

Thx for the reply, AKA Trouble. I’ll try to explain it better.

I have a series of two columns that will contain a lot of raw data. Column B is the controlling column. The values in column A is directly connected to the values in column B.

The first part of my goal is to increment column B by a number specified by the user. I would assume that input needs to come from a message box. After the user has entered their desired increment value, column B is then modified or the new array is copied to another location. This will be my x axis for my graph. I need it to be the same increment every time I run this macro for a different set of data. This value needs to be in nice round numbers.

The second part of my goal is to interpolate the values in column A as the size of column C is decreased.

To interpolate properly the macro needs to search col B for the numbers immediately smaller and larger than the newer, nicer column B value located in column E.

Interpolation eqn: y = y1+(x+x1)*((y2-y1) / (x2-x1))

Where:
y = newly interpolated column B value
y1 = column B value that corresponds to the column A value just less than the newly created column E value.
y2 = column B value that corresponds to the column A value just more than the newly created column E value.
x = column E à revised column B value
x1 = column B value just less than new column E value
x2 = column B value just more than new column E value

Ex. In raw form, column B is incremented by a very small amount (approx. 0.002). I would like to call a message box asking the user to enter an increment value. If the user enters 0.01 as the new increment, then the new values for column B will be:

Column A raw data
Column B raw data
Column D interpolated value
column E revised column B value
0
0
0.000000
0.00
0.000000000000
0.0449829101562500
0.000000
0.04
0.168775439262
0.0499801635742187
0.168775
0.05
0.168775439262
0.0574798583984375
0.168775
0.06
0.168775439262
0.0624771118164062
0.168775
0.07
0.168775439262
0.0674743652343750
0.168775
0.08
0.168775439262
0.0749740600585937
0.168775
0.09
0.168775439262
0.0800018310546875
0.168775
0.1
0.168775439262
0.0875015258789062
0.168775
0.11
0.168775439262
0.0950012207031250
0.281345
0.12
0.168775439262
0.1025009155273440
0.337551
0.13
0.337550967932
0.1074981689453120
0.393880
0.14
0.168775439262
0.1149978637695310
0.393729
0.15
0.337550967932
0.1224975585937500
0.506259
0.16
0.337550967932
0.1299972534179690
0.337613
0.17
0.337550967932
0.1374969482421870
0.506326
0.18
0.506326436996
0.1449966430664060
0.506326
0.19
0.337550967932
0.1524963378906250
0.562711
0.2
0.506326436996
0.1599960327148440
0.562450
0.21
0.337550967932
0.1699981689453120
0.675102
0.22
0.506326436996
0.1749954223632810
0.717271
0.23
0.506326436996
0.1824951171875000
0.562519
0.24

<tbody>
</tbody>


I hope this clears things up a bit. I'm still trying to figure the code out, but getting nowhere. Thanks for your help on this one, everyone.

-Brandon
 
Upvote 0
I know it's a tough one, but any help on any portion would be much appreciated.

Thanks, everyone.
 
Upvote 0

Forum statistics

Threads
1,214,548
Messages
6,120,146
Members
448,948
Latest member
spamiki

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top