PC Review


Reply
Thread Tools Rate Thread

actual value of cell, not reference

 
 
Labrat
Guest
Posts: n/a
 
      19th Jun 2009
I have a macro that replaces values below a number set by the user to "ND".
The problem is it doesn't work when the cell contains a reference to another
cell or workbook.
Is there a way to get the absolute value of the cell and ignore the reference?

Here is what I have so far:

Sub ND()
'
'
Dim rng As Range

a = InputBox("Enter a value." & vbNewLine & "Any values below this will be
replaced by ND", "ND Replace")

If a = "" Or IsNumeric(a) = False Then

Exit Sub

End If
For Each rng In Selection
If Val(rng.Value) < a Or rng.Value = "" Then
rng.Replace what:=rng.Value, replacement:="ND"

End If
Next rng


End Sub

Any help would be appreciated.
Thanks.
 
Reply With Quote
 
 
 
 
Jim Thomlinson
Guest
Posts: n/a
 
      19th Jun 2009
Sub ND()
'
'
Dim rng As Range

a = InputBox("Enter a value." & vbNewLine & "Any values below this will be
replaced by ND", "ND Replace")

If a = "" Or IsNumeric(a) = False Then

Exit Sub

End If
For Each rng In Selection
If Val(rng.Value) < a Or rng.Value = "" Then
rng.Value ="ND"
End If
Next rng

End Sub

--
HTH...

Jim Thomlinson


"Labrat" wrote:

> I have a macro that replaces values below a number set by the user to "ND".
> The problem is it doesn't work when the cell contains a reference to another
> cell or workbook.
> Is there a way to get the absolute value of the cell and ignore the reference?
>
> Here is what I have so far:
>
> Sub ND()
> '
> '
> Dim rng As Range
>
> a = InputBox("Enter a value." & vbNewLine & "Any values below this will be
> replaced by ND", "ND Replace")
>
> If a = "" Or IsNumeric(a) = False Then
>
> Exit Sub
>
> End If
> For Each rng In Selection
> If Val(rng.Value) < a Or rng.Value = "" Then
> rng.Replace what:=rng.Value, replacement:="ND"
>
> End If
> Next rng
>
>
> End Sub
>
> Any help would be appreciated.
> Thanks.

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      19th Jun 2009
Hi,

I think your trying to do this

Sub ND()
Dim rng As Range
a = CLng(InputBox("Enter a value." & vbNewLine & _
"Any values below this will be replaced by ND", "ND Replace"))
If a = vbNullString Or Not IsNumeric(a) Then
Exit Sub
End If

For Each rng In Selection
If rng.Value < a Or rng.Value = "" Then
rng.Replace what:=rng.Value, replacement:="ND"
End If
Next rng
End Sub



Mike

"Labrat" wrote:

> I have a macro that replaces values below a number set by the user to "ND".
> The problem is it doesn't work when the cell contains a reference to another
> cell or workbook.
> Is there a way to get the absolute value of the cell and ignore the reference?
>
> Here is what I have so far:
>
> Sub ND()
> '
> '
> Dim rng As Range
>
> a = InputBox("Enter a value." & vbNewLine & "Any values below this will be
> replaced by ND", "ND Replace")
>
> If a = "" Or IsNumeric(a) = False Then
>
> Exit Sub
>
> End If
> For Each rng In Selection
> If Val(rng.Value) < a Or rng.Value = "" Then
> rng.Replace what:=rng.Value, replacement:="ND"
>
> End If
> Next rng
>
>
> End Sub
>
> Any help would be appreciated.
> Thanks.

 
Reply With Quote
 
Labrat
Guest
Posts: n/a
 
      19th Jun 2009
Thanks!! That was fast. Problem solved.
It seems I was once again over-complicating things.

Thanks again!!

"Jim Thomlinson" wrote:

> Sub ND()
> '
> '
> Dim rng As Range
>
> a = InputBox("Enter a value." & vbNewLine & "Any values below this will be
> replaced by ND", "ND Replace")
>
> If a = "" Or IsNumeric(a) = False Then
>
> Exit Sub
>
> End If
> For Each rng In Selection
> If Val(rng.Value) < a Or rng.Value = "" Then
> rng.Value ="ND"
> End If
> Next rng
>
> End Sub
>
> --
> HTH...
>
> Jim Thomlinson
>
>
> "Labrat" wrote:
>
> > I have a macro that replaces values below a number set by the user to "ND".
> > The problem is it doesn't work when the cell contains a reference to another
> > cell or workbook.
> > Is there a way to get the absolute value of the cell and ignore the reference?
> >
> > Here is what I have so far:
> >
> > Sub ND()
> > '
> > '
> > Dim rng As Range
> >
> > a = InputBox("Enter a value." & vbNewLine & "Any values below this will be
> > replaced by ND", "ND Replace")
> >
> > If a = "" Or IsNumeric(a) = False Then
> >
> > Exit Sub
> >
> > End If
> > For Each rng In Selection
> > If Val(rng.Value) < a Or rng.Value = "" Then
> > rng.Replace what:=rng.Value, replacement:="ND"
> >
> > End If
> > Next rng
> >
> >
> > End Sub
> >
> > Any help would be appreciated.
> > Thanks.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reference cell ID in CUBEVALUE tuple instead of actual value ericblair Microsoft Excel Worksheet Functions 1 7th Oct 2009 05:04 PM
Need Help convert text to actual cell range reference address liang.yuwei@gmail.com Microsoft Excel Discussion 8 6th Jun 2008 05:09 PM
Getting a reference to the actual background worker Jerry Spence1 Microsoft VB .NET 3 11th Feb 2008 04:29 PM
Go to from reference in VBA code to actual cell? John Dalberg Microsoft Excel Programming 5 16th Sep 2006 03:15 PM
problem with cell reference in =sum(offset(cell reference,x,y,z,a)). Want cell ref to be variable. twister212atop@yahoo.com Microsoft Excel Worksheet Functions 2 11th Dec 2004 12:05 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:03 PM.