Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Ranges in VBA

Hello all:

I have a user defined function that uses range names as an imput.

This function look for some data in the ranges named (you can see this
function below, it is short).

The problem is that when I copy and paste some values in the range the
functions don´t actualize always, nothing change in calculations.

I don´t have this problem if I introduce the values one by one manually, but
it occurs if I use copy and paste.

Sometimes even it doesn´t work pressing F9 and I need to press Alt+Ctrl+F9,
I´d like to be able to use this function as any other one in Excel, without
recalculation problems. Can anybody help.

Thank in advance.

Important note: I usually use the function in one worksheet and the data
ranges are in other worksheet.


Public Function LookInTable(TableName As String, ColVal As String, RowVal As
String) As Variant

Application.Volatile
Dim i As Long, rw As Long, col As Long

With Range(TableName)

For i = 1 To .Columns.Count
If .Cells(1, i).Value = RowVal Then
col = i
Exit For
End If
Next

For i = 1 To .Rows.Count
If .Cells(i, 1).Value = ColVal Then
rw = i
Exit For
End If
Next

End With

LookInTable= Application.Evaluate("=Index(" & TableName & "," & _
rw & "," & col & ")")
End Function


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Ranges in VBA

The string thing is tripping you up. Consider two functions:

Function zum(r As Range) As Variant
zum = r.Value
End Function

and the function

Function zun(s As String) As Variant
Set r = Range(s)
zun = r.Value
End Function

In the worksheet we have defined mycell as cell A10. In two other cells we
enter:

=zum(mycell)
=zun("mycell")

Both functions work the first time they are entered. If we start updating
A10 either with edits or paste, zum responds and zun does not. This is true
even though zum has no Volatile statement in it.

Change both your code and the worksheet cells to pass the Named Range as a
range, not a string.




--
Gary''s Student - gsnu2007d


"Mnilo" wrote:

Hello all:

I have a user defined function that uses range names as an imput.

This function look for some data in the ranges named (you can see this
function below, it is short).

The problem is that when I copy and paste some values in the range the
functions don´t actualize always, nothing change in calculations.

I don´t have this problem if I introduce the values one by one manually, but
it occurs if I use copy and paste.

Sometimes even it doesn´t work pressing F9 and I need to press Alt+Ctrl+F9,
I´d like to be able to use this function as any other one in Excel, without
recalculation problems. Can anybody help.

Thank in advance.

Important note: I usually use the function in one worksheet and the data
ranges are in other worksheet.


Public Function LookInTable(TableName As String, ColVal As String, RowVal As
String) As Variant

Application.Volatile
Dim i As Long, rw As Long, col As Long

With Range(TableName)

For i = 1 To .Columns.Count
If .Cells(1, i).Value = RowVal Then
col = i
Exit For
End If
Next

For i = 1 To .Rows.Count
If .Cells(i, 1).Value = ColVal Then
rw = i
Exit For
End If
Next

End With

LookInTable= Application.Evaluate("=Index(" & TableName & "," & _
rw & "," & col & ")")
End Function



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Ranges in VBA

This solution only works if the ranges are in the same worksheet, but it
doesn´t work in other case

Any other suggestion??

Thanks in any case.


"Gary''s Student" escribió en el
mensaje ...
The string thing is tripping you up. Consider two functions:

Function zum(r As Range) As Variant
zum = r.Value
End Function

and the function

Function zun(s As String) As Variant
Set r = Range(s)
zun = r.Value
End Function

In the worksheet we have defined mycell as cell A10. In two other cells
we
enter:

=zum(mycell)
=zun("mycell")

Both functions work the first time they are entered. If we start updating
A10 either with edits or paste, zum responds and zun does not. This is
true
even though zum has no Volatile statement in it.

Change both your code and the worksheet cells to pass the Named Range as a
range, not a string.




--
Gary''s Student - gsnu2007d


"Mnilo" wrote:

Hello all:

I have a user defined function that uses range names as an imput.

This function look for some data in the ranges named (you can see this
function below, it is short).

The problem is that when I copy and paste some values in the range the
functions don´t actualize always, nothing change in calculations.

I don´t have this problem if I introduce the values one by one manually,
but
it occurs if I use copy and paste.

Sometimes even it doesn´t work pressing F9 and I need to press
Alt+Ctrl+F9,
I´d like to be able to use this function as any other one in Excel,
without
recalculation problems. Can anybody help.

Thank in advance.

Important note: I usually use the function in one worksheet and the data
ranges are in other worksheet.


Public Function LookInTable(TableName As String, ColVal As String, RowVal
As
String) As Variant

Application.Volatile
Dim i As Long, rw As Long, col As Long

With Range(TableName)

For i = 1 To .Columns.Count
If .Cells(1, i).Value = RowVal Then
col = i
Exit For
End If
Next

For i = 1 To .Rows.Count
If .Cells(i, 1).Value = ColVal Then
rw = i
Exit For
End If
Next

End With

LookInTable= Application.Evaluate("=Index(" & TableName & "," & _
rw & "," & col & ")")
End Function





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Ranges in VBA

It don't see the failure.

=zum(mycell)

give updated results in which ever sheet the formula is entered. Even
though mycell is a Named Range on Sheet1, the Name is visible on any sheet in
the workbook.

Start with a completely new workbook and try zum().

--
Gary''s Student - gsnu200768


"Mnilo" wrote:

This solution only works if the ranges are in the same worksheet, but it
doesn´t work in other case

Any other suggestion??

Thanks in any case.


"Gary''s Student" escribió en el
mensaje ...
The string thing is tripping you up. Consider two functions:

Function zum(r As Range) As Variant
zum = r.Value
End Function

and the function

Function zun(s As String) As Variant
Set r = Range(s)
zun = r.Value
End Function

In the worksheet we have defined mycell as cell A10. In two other cells
we
enter:

=zum(mycell)
=zun("mycell")

Both functions work the first time they are entered. If we start updating
A10 either with edits or paste, zum responds and zun does not. This is
true
even though zum has no Volatile statement in it.

Change both your code and the worksheet cells to pass the Named Range as a
range, not a string.




--
Gary''s Student - gsnu2007d


"Mnilo" wrote:

Hello all:

I have a user defined function that uses range names as an imput.

This function look for some data in the ranges named (you can see this
function below, it is short).

The problem is that when I copy and paste some values in the range the
functions don´t actualize always, nothing change in calculations.

I don´t have this problem if I introduce the values one by one manually,
but
it occurs if I use copy and paste.

Sometimes even it doesn´t work pressing F9 and I need to press
Alt+Ctrl+F9,
I´d like to be able to use this function as any other one in Excel,
without
recalculation problems. Can anybody help.

Thank in advance.

Important note: I usually use the function in one worksheet and the data
ranges are in other worksheet.


Public Function LookInTable(TableName As String, ColVal As String, RowVal
As
String) As Variant

Application.Volatile
Dim i As Long, rw As Long, col As Long

With Range(TableName)

For i = 1 To .Columns.Count
If .Cells(1, i).Value = RowVal Then
col = i
Exit For
End If
Next

For i = 1 To .Rows.Count
If .Cells(i, 1).Value = ColVal Then
rw = i
Exit For
End If
Next

End With

LookInTable= Application.Evaluate("=Index(" & TableName & "," & _
rw & "," & col & ")")
End Function






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Ranges in VBA

Ok,

I started up Excel again and it worked very well.

Thanks for your help.
"Gary''s Student" escribió en el
mensaje ...
It don't see the failure.

=zum(mycell)

give updated results in which ever sheet the formula is entered. Even
though mycell is a Named Range on Sheet1, the Name is visible on any sheet
in
the workbook.

Start with a completely new workbook and try zum().

--
Gary''s Student - gsnu200768


"Mnilo" wrote:

This solution only works if the ranges are in the same worksheet, but it
doesn´t work in other case

Any other suggestion??

Thanks in any case.


"Gary''s Student" escribió en el
mensaje ...
The string thing is tripping you up. Consider two functions:

Function zum(r As Range) As Variant
zum = r.Value
End Function

and the function

Function zun(s As String) As Variant
Set r = Range(s)
zun = r.Value
End Function

In the worksheet we have defined mycell as cell A10. In two other
cells
we
enter:

=zum(mycell)
=zun("mycell")

Both functions work the first time they are entered. If we start
updating
A10 either with edits or paste, zum responds and zun does not. This is
true
even though zum has no Volatile statement in it.

Change both your code and the worksheet cells to pass the Named Range
as a
range, not a string.




--
Gary''s Student - gsnu2007d


"Mnilo" wrote:

Hello all:

I have a user defined function that uses range names as an imput.

This function look for some data in the ranges named (you can see this
function below, it is short).

The problem is that when I copy and paste some values in the range
the
functions don´t actualize always, nothing change in calculations.

I don´t have this problem if I introduce the values one by one
manually,
but
it occurs if I use copy and paste.

Sometimes even it doesn´t work pressing F9 and I need to press
Alt+Ctrl+F9,
I´d like to be able to use this function as any other one in Excel,
without
recalculation problems. Can anybody help.

Thank in advance.

Important note: I usually use the function in one worksheet and the
data
ranges are in other worksheet.


Public Function LookInTable(TableName As String, ColVal As String,
RowVal
As
String) As Variant

Application.Volatile
Dim i As Long, rw As Long, col As Long

With Range(TableName)

For i = 1 To .Columns.Count
If .Cells(1, i).Value = RowVal Then
col = i
Exit For
End If
Next

For i = 1 To .Rows.Count
If .Cells(i, 1).Value = ColVal Then
rw = i
Exit For
End If
Next

End With

LookInTable= Application.Evaluate("=Index(" & TableName & "," & _
rw & "," & col & ")")
End Function








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
how copy formula that contains ranges so ranges do not overlap Patty Excel Worksheet Functions 1 November 20th 08 04:15 PM
Named ranges scope / workbook/worksheet level named ranges- changeswith variable use... christian_spaceman Excel Programming 3 December 24th 07 01:15 PM
union of named ranges based only on the names of those ranges sloth Excel Programming 3 October 2nd 06 03:18 AM
Copy data in named ranges to a newer version of the same template to identical ranges handstand Excel Programming 0 August 21st 06 03:51 PM
named ranges - changing ranges with month selected gr8guy Excel Programming 2 May 28th 04 04:50 AM


All times are GMT +1. The time now is 10:08 PM.

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"