Modify VBA with VBA

MrKowz

Well-known Member
Joined
Jun 30, 2008
Messages
6,653
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hey all,

I have read the article by Chip Pearson (http://www.cpearson.com/Excel/vbe.aspx), and I have a question that isn't quite touched on in there.

Is it possible to edit a specific line in a module through a procedure? I am leaving the company I am with at the end of the week, and I am trying to build the most effective way for my employer to continue to use a program I have written (whose code has several areas that is dependent on the naming convention of the workbooks that are opened).

It WOULD be possible for me to go through the code and adapt it for the workbook name through a variable, but I simply don't have time to accomplish this.

Basically, I need to change the following to a specific inputbox value
Module: Sheet1
  • Line 9, Col 72 through Line 9, Col 80
  • Line 21, Col 57 through Line 21, Col 65
  • Line 32, Col 85 through Line 32, Col 93
In each of those line/columns, I am effectively changing the word "Template" to the inputbox value (variable length). I just don't know how to specifically change those lines through VBA.

If I can get a solution to this, I am confident I can build the solution for other modules.

Thanks in advance!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Code:
Sub testlkj23ljk4234jkl()
Dim myValue As String

myValue = InputBox(prompt:="Enter value")
    Sheet1.Range("BT9:CB9").Value = myValue
End Sub
 
Upvote 0
Code:
Sub testlkj23ljk4234jkl()
Dim myValue As String
 
myValue = InputBox(prompt:="Enter value")
    Sheet1.Range("BT9:CB9").Value = myValue
End Sub
I don't need to adjust the worksheet, I need to adjust the actual visual basic code.
 
Upvote 0
It WOULD be possible for me to go through the code and adapt it for the workbook name through a variable, but I simply don't have time to accomplish this.

I'm not sure I see why adding a variable/function to replace a hardcoded value takes a long time. Just find and replace (find: template replace with: my_input_box_function).

Heck, if its three lines, you don't even need find/replace.
 
Last edited:
Upvote 0
I'm not sure I see why adding a variable/function to replace a hardcoded value takes a long time. Surely no less troublesome than writing code to write code. Just find and replace (find: template replace with: my_input_box_function).

I won't be able to modify the current code to adapt with a variable/function unless I'm at work due to confidentiality; and I am booked 100% through the end of tomorrow, my last day. The other code I can work on at home since I know what specific line/cols to replace.
 
Upvote 0
You can't modify the code with a variable, but you *can* modify the code with more code? Not sure I understand ... :(
 
Upvote 0
I'd be able to create the code at home, off the clock, then when I get in tomorrow I'd be able to just copy the code into the current workbook.

Also, this is for my own understanding and education to further my knowledge in Excel. :biggrin:
 
Upvote 0
I figured as much from you. But I'm no hand at writing code to write code. It seems the long way around to me (just write the new code, then copy that in tomorrow). But as they say, to each his own ...
 
Upvote 0
So you can't find and replace at home?

I can understand you want to learn about this but if this needs to be done quickly then it might be easier to just to find/replace.

At least you'll get it done.:)

You could even copy the code somewhere else if you want a more powerful find/replace than that available in the VBE.
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,776
Members
452,942
Latest member
VijayNewtoExcel

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