macro to find and replace within VBA code

surlybiker

New Member
Joined
Jul 1, 2011
Messages
14
I'm not even sure if this is possible, but here goes.

Here is my particular need in a nutshell: Is there a way for a macro to look at a worksheet (entitled "Sheet1" which is the first sheet in a workbook entitled "Sheet_1.xls"), find the last row of data, and then replace three particular numbers in the VBA code of another workbook (entitled "Sample.xlsm") with the sum of that "last row of data" number and 17.

An example: if the last row of data on Sheet1 is 350, the macro would look within existing macro code (of the Sample.xlsm workbook) and find the numbers 4997, 4998, and 5008 and replace them with 367, 368, and 378, respectively. If the last row was 3,100, it would find and replace those numbers (4997, 4998, and 5008) with 3117, 3118, and 3128.

It is likely that, being an amateur, my existing code is extremely poorly written. However, in the event my request is even possible, I thought I'd throw it out there.

Thanks so much for the help!
 
Thanks so much for the tooltip tip. I moused over it and it said it was empty. I realized I hadn't been putting in the code to actually identify what the last row was. Novice mistake. I placed this in each module (not sure if this was necessary) and it finally worked.

I appreciate your help, GlennUK! Many thanks.
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,224,585
Messages
6,179,696
Members
452,938
Latest member
babeneker

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