View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
GS[_6_] GS[_6_] is offline
external usenet poster
 
Posts: 1,182
Default 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 columns 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 this inserting the rows, I have to
linear interpolate columns C, D & E in the newly create empty
columns. 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.


My approach would be to separate adding more rows from the business
logic. I use something like this...


Sub InsertBlankRows(Optional Position As String)
' Inserts a specified number of rows at the location specified.
' If the Position arg is not used then the default is ActiveCell.Row.
Dim vRows As Variant, lPos As Long
Const sMsg As String = "Enter the number of rows to insert."

'Evaluate user input
On Error Resume Next
vRows = InputBox(Prompt:=sMsg, Default:=1): If vRows = "" Then Exit
Sub '//user cancels
If Not Err = 0 Or Not IsNumeric(vRows) Or Not vRows = 1 Then Exit
Sub

'Get the position to insert
lPos = IIf(Position = "Below", lPos + 1, ActiveCell.Row)

'Insert the rows
ActiveSheet.Rows(lPos).Resize(vRows).Insert Shift:=xlDown
End Sub 'InsertBlankRows

...and use it like this...

Sub AddMoreRows()
Dim vAns, sPos$
vAns = MsgBox("Insert rows ABOVE here?", vbYesNo, "Insert Rows")
sPos = IIf(vAns = vbYes, "Above", "Below")
InsertBlankRows sPos
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion