Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 339
Default Cell validation problem

Hi

I have a function which takes a cell reference as a parameter. The function
is similar to this

Function MyRef(wb As String, ws As String, cell As String)
MyRef = Application.Evaluate("[" + wb + ".xls]" + ws + "!" + cell)
End Function

The idea behind this function is simple. Instead of entering something like
this:

=[SomeSheet.xls]Sheet1!A1

I can now do this:

=MyRef("SomeSheet","Sheet1","A1")

How can I validate the last parameter? "A1" is a valid cell reference while
"XX23" isn't.
I want to to show a custom error messsage in this case.

TIA,
Fredrik


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Cell validation problem

Hi
not really sure why you're doing this (as this slows down Excel and you may
use INDIRECT instead). But maybe enclose your function in an
on error resume next
statement and check err.number afterwards

--
Regards
Frank Kabel
Frankfurt, Germany
"Fredrik Wahlgren" schrieb im
Newsbeitrag ...
Hi

I have a function which takes a cell reference as a parameter. The
function
is similar to this

Function MyRef(wb As String, ws As String, cell As String)
MyRef = Application.Evaluate("[" + wb + ".xls]" + ws + "!" + cell)
End Function

The idea behind this function is simple. Instead of entering something
like
this:

=[SomeSheet.xls]Sheet1!A1

I can now do this:

=MyRef("SomeSheet","Sheet1","A1")

How can I validate the last parameter? "A1" is a valid cell reference
while
"XX23" isn't.
I want to to show a custom error messsage in this case.

TIA,
Fredrik




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 339
Default Cell validation problem


"Frank Kabel" wrote in message
...
Hi
not really sure why you're doing this (as this slows down Excel and you

may
use INDIRECT instead). But maybe enclose your function in an
on error resume next
statement and check err.number afterwards

--
Regards
Frank Kabel
Frankfurt, Germany
"Fredrik Wahlgren" schrieb im
Newsbeitrag ...


I don't think I can use INDIRECT with external sheets. The idea is to have a
master sheet in which I get data from othe sheets generated by a program.
The sheets change every month so I want to have a way to quickly change the
reference. It doesn't matter that it slows down Excel. The names of the
generated sheets change in a predictable way.

/ Fredrik


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default Cell validation problem

Fredrik

One way



Function MyRef(wb As String, ws As String, cell As String)


Dim rTest as Range

On Error Resume Next
Set rTest = ActiveSheet.Range(cell)
On Error Goto 0

If rTest Is Nothing Then
MyRef = "Invalid Cell Reference"
Else
MyRef = Application.Evaluate("[" + wb + ".xls]" + ws + "!" + cell)


End If

End Function


How can I validate the last parameter? "A1" is a valid cell reference
while "XX23" isn't.
I want to to show a custom error messsage in this case.


--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 339
Default Cell validation problem


"Dick Kusleika" wrote in message
...
Fredrik

One way
Function MyRef(wb As String, ws As String, cell As String)


Dim rTest as Range

On Error Resume Next
Set rTest = ActiveSheet.Range(cell)
On Error Goto 0

If rTest Is Nothing Then
MyRef = "Invalid Cell Reference"
Else
MyRef = Application.Evaluate("[" + wb + ".xls]" + ws + "!" + cell)


End If

End Function


Yes, this seems to solve the problem. I have to admit that I thought there
was another way to do this, one that wouldn't result in a run time error.

Thank you,
Fredrik




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default Cell validation problem



Yes, this seems to solve the problem. I have to admit that I thought there
was another way to do this, one that wouldn't result in a run time error.


Other than string manipulation, I can't think of a way.

Function IsValidRange(sInput As String) As Boolean

Dim sCol As String
Dim lRow As Long
Dim i As Long

For i = 1 To Len(sInput)
If IsNumeric(Mid(sInput, i, 1)) Then
If IsNumeric(Mid(sInput, i)) Then
lRow = CLng(Mid(sInput, i))
Exit For
Else
IsValidRange = False
Exit Function
End If
Else
sCol = sCol & Mid(sInput, i, 1)
End If
Next i

If lRow ActiveSheet.Rows.Count Then
IsValidRange = False
Else
If sCol "IV" Then
IsValidRange = False
Else
IsValidRange = True
End If
End If

End Function

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 339
Default Cell validation problem

Hi Dick

Thank you very much.

/ Fredrik

"Dick Kusleika" wrote in message
...


Yes, this seems to solve the problem. I have to admit that I thought

there
was another way to do this, one that wouldn't result in a run time

error.


Other than string manipulation, I can't think of a way.

Function IsValidRange(sInput As String) As Boolean

Dim sCol As String
Dim lRow As Long
Dim i As Long

For i = 1 To Len(sInput)
If IsNumeric(Mid(sInput, i, 1)) Then
If IsNumeric(Mid(sInput, i)) Then
lRow = CLng(Mid(sInput, i))
Exit For
Else
IsValidRange = False
Exit Function
End If
Else
sCol = sCol & Mid(sInput, i, 1)
End If
Next i

If lRow ActiveSheet.Rows.Count Then
IsValidRange = False
Else
If sCol "IV" Then
IsValidRange = False
Else
IsValidRange = True
End If
End If

End Function

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com




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
Validation Data using Validation Table cell range..... Dermot Excel Discussion (Misc queries) 16 January 5th 10 09:35 PM
Validation Problem Charles Excel Discussion (Misc queries) 3 August 25th 08 01:50 PM
Validation problem. Petter Excel Worksheet Functions 3 December 19th 07 03:13 PM
Validation problem... BeSmart Excel Worksheet Functions 3 July 7th 05 02:22 AM
Validation problem GMet Excel Programming 3 October 7th 04 02:30 AM


All times are GMT +1. The time now is 02:52 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"