VBA to make part of current selection absolute

norts55

Board Regular
Joined
Jul 27, 2012
Messages
191
Please help. This seems simple but I have exhausted everything I can think of.

Is there a way after my selection is made to make part of a formula absolute?
Below is a simple formula that I have in a cell. This formula can be referring to any cells, not just the cells I am referring to.
I have a macro that is using some search criteria to select a cell with this formula, once the cell is selected I need the F675 to be $F$675 (absolute). But remember this can be any cell reference. I hope this makes sense. If not, please let me know and I can try to explain better.

Is now "=(I681*F675)"
Needs to be "=(I681*$F$675)"
 
Here I have it working with this

Book1
ABC
100
2
3
4
296135 - GSO
Cell Formulas
RangeFormula
A1A1=G1*$E$1
C1C1=(G1*E1)



VBA Code:
Public Function MakeAbsolute(inRng As Range) As String
    Dim form As Variant

    form = Split(inRng.Formula, "*")
    MakeAbsolute = Replace(form(0), "(", "") & "*" & Application.ConvertFormula(Replace(form(1), ")", ""), xlA1, xlA1, 1)
End Function


Public Sub TestIt()
    Range("A1").Formula = MakeAbsolute(Range("C1"))
End Sub
 
Upvote 0

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
C1 is empty also.
That is why you are getting the error, because it you are running the exact code he posted, it is trying to apply that to cell C1, as indicated here:
Rich (BB code):
Public Sub TestIt()
    Range("A1").Formula = MakeAbsolute(Range("C1"))
End Sub
You need to change the "C1" in that formula to the cell you want to run this against (where your current formula resides).
And you need to change the "A1" to the cell that you want the result to go into. If you want to to update the current formula, both these cells should be the same value.
 
Upvote 0
Sorry for my lack of understanding. Coding is way beyond my skill set and I maybe making this more frustrating and confusing than it really is. But what I am thinking is, I need this to run against in my active (currently picked) cell as I will be picking cells anywhere on my sheet that have this formula. The dynamic formula you gave me in post #10 works great, just not with parenthesis. Is there a way to make that formula work with parenthesis?
 
Upvote 0
Sorry for my lack of understanding. Coding is way beyond my skill set and I maybe making this more frustrating and confusing than it really is. But what I am thinking is, I need this to run against in my active (currently picked) cell as I will be picking cells anywhere on my sheet that have this formula. The dynamic formula you gave me in post #10 works great, just not with parenthesis. Is there a way to make that formula work with parenthesis?
Note that the parentheses really serve no purpose in that formula and really do not need to be there.

But try this version, which will handle either case (with or without parentheses).
VBA Code:
Public Sub UpdateFormula()
    Dim form As Variant
    form = Split(ActiveCell.Formula, "*")
    If Right(form(1), 1) = ")" Then
        ActiveCell.Formula = form(0) & "*" & Application.ConvertFormula(Left(form(1), Len(form(1)) - 1), xlA1, xlA1, 1) & ")"
    Else
        ActiveCell.Formula = form(0) & "*" & Application.ConvertFormula(form(1), xlA1, xlA1, 1)
    End If
End Sub
 
Upvote 0
Solution
That works perfectly. Thank you!

I agree, the parentheses don't need to be there. These are old formulas, that I did not create and copied hundreds of times.

You solved my issue. Thank you very much.
 
Upvote 0
You are welcome.
Glad we were able to help!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top