Excel Visual Basic Macro Partial Formula Replacement.

Anonymous
2022-05-31T22:44:45+00:00

I am trying to create a macro in excel visual basic to replace part of a formula in a cell. I have an input box to allow the user to specify the new number, and a replace function to replace the value. (Just for good measure, I made the range include the cell with the formula and a few blank cells around it.) When I run my macro, it fills in the blank cells with the new value, but does not replace needed value in excel.

I am wanting the unchanged value to be XXXX and want to allow the user to input their own value which would correspond with the necessary excel file they are needing to retrieve their data from.

This is what I currently have:

Sub Replace_XXXX_and_YYYY()

SN1 = InputBox("Enter 1st Serial Number")

SN2 = InputBox("Enter 2nd Serial Number")

Range("B9:B11").Replace What:=XXXX, Replacement:=SN1

Range("B9:B11").Replace What:=YYYY, Replacement:=SN2

End Sub

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2022-05-31T23:02:07+00:00

    Dear Jacob,

    Good day!

    Thanks for posting in Microsoft Community.

    We would love to help you on your query about VBA code, however, our team focuses on general query, for example, installation and activation issue of Office 365 products. The situation you mentioned is related to VBA code, you can to refer to this article: Office VBA support and feedback | Microsoft Docs to go to Stack Overflow by using the VBA tag, along with any other relevant tags as there are also many experienced engineers and experts in the forums there.

    Disclaimer: Microsoft provides no assurances and/or warranties, implied or otherwise, and is not responsible for the information you receive from the third-party linked sites, or any support related to technology.

    At the same time, we will also keep this thread open, so other Community members and Experts can also share their suggestions and inputs.

    Thank you for your cooperation and understanding!

    Best Regards,

    Sukie

    0 comments No comments