Help automating updating columns (find and replace) with macros.

Stacker

Board Regular
Joined
Jul 11, 2021
Messages
87
Office Version
  1. 365
Platform
  1. Windows
I routinely get files and people here have helped me with automating one component. However I wanna create a macros that allows m to automate the updating of certain worksheets. I am given an excel file with three tabs.

In the first tab i get a lot of hospital data and one of my tasks is to to copy the last column say MG and paste it into the MH. All of the cells in the column follow a certain formula. The top being like so:

=SUM('\\sancifs\Public_Health\Shared\PH Intelligence\Data\PHI_Data_Intelligence_System\1-PHI_DI_SYS_RAW-IMPORT\COVID-19_data\Hospital_reporting\Both Trusts\[270821 HRI.xlsx]Daily sitrep'!$F$8:$F$11)

I have to paste this column into the next and from there ctrl and f and find and replace. So I would find and replace 270821 with 280821 solely in that column.

Is there a way to copy and paste the previous column and then find and replace by incrememnts of 1 day using a macro.

The second and third stuff are fairly quick so I am not bothered
 
=SUM('\\sancifs\Public_Health\Shared\PH Intelligence\Data\PHI_Data_Intelligence_System\1-PHI_DI_SYS_RAW-IMPORT\COVID-19_data\Hospital_reporting\Both Trusts\["& TEXT(D$2;"ddmmyy")&" HRI.xlsx]Daily sitrep'!$F$8:$F$11)

The data is in D2 but the reference still fails
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
We're in need of the INDIRECT worksheet function.
Excel Formula:
=SUM(INDIRECT("'\\sancifs\Public_Health\Shared\PH Intelligence\Data\PHI_Data_Intelligence_System\1-PHI_DI_SYS_RAW-IMPORT\COVID-19_data\Hospital_reporting\Both Trusts\["& TEXT(D$2;"ddmmyy")&" HRI.xlsx]Daily sitrep'!$F$8:$F$11"))
 
Upvote 0
It refers to the D2 this time (as in D2 turns blue) but there is an error messaging saying there is a problem with this formula.
 
Upvote 0
In my situation (with a much shorter pathname) it works, provided the top row contains valid dates. Dragging this formula to the right and downwards results in an expected outcome.
Be sure that the single quotes and double quotes are on the right spot.

TargetBookWithLinks.xlsx
ABC
14-okt5-okt6-okt
2041021051021061021
32323015
4356353019
547991018612
Sheet1
Cell Formulas
RangeFormula
A2:C2A2=A1
A3:C3A3=SUM(INDIRECT("'F:\TEST\[Book" & TEXT(A$2,"ddmmjj") & " Source.xlsx]Sheet1'!$A$1:$B$1"))
A4:C4A4=SUM(INDIRECT("'F:\TEST\[Book" & TEXT(A$2,"ddmmjj") & " Source.xlsx]Sheet1'!$A$1:$C$1"))
A5:C5A5=SUM(INDIRECT("'F:\TEST\[Book" & TEXT(A$2,"ddmmjj") & " Source.xlsx]Sheet1'!$B$1:$D$1"))
 
Upvote 0
It still says there is problem with the formula. The formula should refer to a particular file. I was hoping the file should produce something like "240821 HRI" within the formula.

=SUM(INDIRECT("'\\sancifs\Public_Health\Shared\PH Intelligence\Data\PHI_Data_Intelligence_System\1-PHI_DI_SYS_RAW-IMPORT\COVID-19_data\Hospital_reporting\Both Trusts\["& TEXT(D$2;"ddmmyy")&" HRI.xlsx]Daily sitrep'!$F$8:$F$11"))

This formula should get data from inside the files being referred to.

Could a bracket be missing?
 
Upvote 0
A closer look tells me, where I have the dates on row 1 and the custom formatting (to match the filename) on row 2, you have it the other way around :eek:
In your formula, D$2 must therefore become D$1.
 
Upvote 0
I thought that but still says there is a mistake on the formula.
 
Last edited:
Upvote 0
still says there is a mistake on the formula.
I copied your formula and pasted it into an editor. The single and double quotes are in the right place, even the space in the filename is there, so it should work.


Why is sum used when I am not adding anything I am just collecting data from inside a file.
I don't know, you came up with it on your post #17.
 
Upvote 0
I copied your formula and pasted it into an editor. The single and double quotes are in the right place, even the space in the filename is there, so it should work.



I don't know, you came up with it on your post #17.
Apologies i only noticed sum was in my other formulas. My fault.
 
Upvote 0
c50a1eb6-8231-41e1-802d-5ef918806a3e


I get this.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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