Using macro to change a formula

  • Hi,


    I have a big range and within each cells I have something like
    =BV1 - sum(), BV2 - sum(), BV3- sum()


    The formula for these cells are okay, except that I need to change
    each to BK instead of BV ... and keep whatever in sum() the same


    What VBA codes can I write so I can go to each cells' formula, and just
    change the "V" to "K" ..?


    Thanks!!


    Kim

  • Presumably you don't want to just use Find and Replace because there are other BV references? Try the code below, which works on the selected cells.
    [vba]Sub FixSelection()
    Dim c As Range, s As String
    For Each c In Selection
    s = c.Formula
    If Left(s, 3) = "=BV" Then
    s = "=BK" & Mid(s, 4)
    c.Formula = s
    End If
    Next c
    End Sub[/vba]

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!