Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 265
Default a With missing and I don´t know where and how to put it

I, I have this macro that look for a value between 2 numbers in column x and
the interpolate for a given value, the macro is:

Sub inter()
Dim Value
Dim a, P As Integer
Dim XRange As Range
Dim YRange As Range

Value = 5.5 'value given by the user (could be textbox1)
a = 1
Set XRange = Range("a1:a600")
Set YRange = Range("b1:b600")
While a < XRange.Rows.Count
If Value Cells(a, 1) And Value < Cells(a + 1, 1) Then
P = a
Xs = Array(.Index(XRange.Value2, P, 1), .Index(XRange.Value2, P + 1,
1))
Ys = Array(.Index(YRange.Value2, P, 1), .Index(YRange.Value2, P
+ 1, 1))
Interpolate = .Forecast(Value, Ys, Xs)
MsgBox Interpolate
Else
a = a + 1
End If
Wend
End Sub

I know that those .Index and .Forecast needs a "with" and "end with"
but I don't know what kind of with (I thought With activeworksheet but it
didn't work)
so could someone tell me how to make my macro run????
TIA
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default a With missing and I don´t know where and how toput it

Maybe...

Option Explicit
Sub inter()
Dim myValue As Variant
Dim a As Long
Dim P As Long
Dim XRange As Range
Dim YRange As Range
Dim Xs As Variant
Dim Ys As Variant
Dim Interpolate As Double

myValue = 5.5 'myValue given by the user (could be textbox1)
a = 1
Set XRange = Range("a1:a600")
Set YRange = Range("b1:b600")
While a < XRange.Rows.Count
If myValue Cells(a, 1) And myValue < Cells(a + 1, 1) Then
P = a
With Application
Xs = Array(.Index(XRange.Value2, P, 1), _
.Index(XRange.Value2, P + 1, 1))
Ys = Array(.Index(YRange.Value2, P, 1), _
.Index(YRange.Value2, P + 1, 1))
Interpolate = .Forecast(myValue, Ys, Xs)
End With
MsgBox Interpolate
Else
a = a + 1
End If
Wend
End Sub

I wouldn't use a variable by the name of Value. It may not confuse excel, but
it sure would confuse me.


filo666 wrote:

I, I have this macro that look for a value between 2 numbers in column x and
the interpolate for a given value, the macro is:

Sub inter()
Dim Value
Dim a, P As Integer
Dim XRange As Range
Dim YRange As Range

Value = 5.5 'value given by the user (could be textbox1)
a = 1
Set XRange = Range("a1:a600")
Set YRange = Range("b1:b600")
While a < XRange.Rows.Count
If Value Cells(a, 1) And Value < Cells(a + 1, 1) Then
P = a
Xs = Array(.Index(XRange.Value2, P, 1), .Index(XRange.Value2, P + 1,
1))
Ys = Array(.Index(YRange.Value2, P, 1), .Index(YRange.Value2, P
+ 1, 1))
Interpolate = .Forecast(Value, Ys, Xs)
MsgBox Interpolate
Else
a = a + 1
End If
Wend
End Sub

I know that those .Index and .Forecast needs a "with" and "end with"
but I don't know what kind of with (I thought With activeworksheet but it
didn't work)
so could someone tell me how to make my macro run????
TIA


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
hiding all cells that dont have any text Misho Excel Discussion (Misc queries) 5 September 27th 09 01:59 PM
Kinda like a database - I cant believe others dont need to do th Bob Excel Discussion (Misc queries) 3 December 12th 08 03:02 PM
I don´t view the value right after six decimal place in Excel Claudio Excel Discussion (Misc queries) 4 August 6th 08 12:58 PM
Dont want member number to repeat in the same column. TPkk Excel Discussion (Misc queries) 1 October 29th 06 09:21 PM
Don´t show Updatelinks prompt and don´t update Kent Excel Programming 4 August 26th 04 05:50 PM


All times are GMT +1. The time now is 09:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"