View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bubu Bubu is offline
external usenet poster
 
Posts: 21
Default Formula Tool, Help Required.

Ref. Excel 97

I use a macro to programmatically substitute a certain value from a
formula,

If i want to substitute "A18" whith "B17" in the following formula

=IF(LEN(A18)=0,"",IF(ISERR(FIND(" ",A18)),A18,LEFT(A18,FIND("
",A18)-1)))



I select the cell containing the formula and i Run my macro, that has
two inputbox, one for the old value to be replaced in the formula, one
for the new value.

To select the Old and New values in the inputbox, i have two ways.
1) entereing values in the inputbox manually.
2) selecting a cell, for example range "B17",
( in the inputbox i see B17, but if i change selection in F15 and i go
back in B17, the inputbox show $B$17, and i don't like that).




I go around useing something like
..Address(False, False) instead of .Address.

The following Macro works but, i don't like to see $B$17.
if i want absolute reference i enter $ manually.


Any Help Apreciated.

Best Regards.
Robert.







'This is My Macro

Sub a__Replace_Input_range_2()
On Error Resume Next

Dim My_Default As String

If ActiveCell.Column 1 Then
My_Default = ActiveCell.Offset(0, -1).Address(False, False)
Else

If ActiveCell.Row 1 Then
My_Default = ActiveCell.Offset(-1, 0).Address(False, False)
End If
End If

Dim Old_Value As Range
Dim New_Value As Range

Set Old_Value = Application.InputBox(prompt:="Select Old",
Title:="Title", Default:=My_Default, Type:=8)
If Old_Value Is Nothing Then
MsgBox "Good By"
Exit Sub
End If

Set New_Value = Application.InputBox(prompt:="Select New",
Title:="Title", Default:=My_Default, Type:=8)
If New_Value Is Nothing Then
MsgBox "Good By"
Exit Sub
End If

Selection.Replace What:=Old_Value.Address(False, False),
Replacement:=New_Value.Address(False, False)
End Sub