I have 100 different worksheets (1 for each cost center) with forecast values all in the same spot, but in an unusable format. I have written a query that formats everything nicely, but due to the changes that are made to the data, each sheet must be run through the query separately. I am trying to automate it so I am not spending several hours every period duplicating the query and changing the source, but cannot find a good way to do so. My initial idea is to have all the sheets in one workbook and have VBA duplicate the query and change source name for each cost center listed on a locations sheet. Is it possible to make a loop in vba that alters M code? Or is there a solution in PQ that I have not found on google.
Here is the source part of my M code and what I would like to change:
Source = Excel.Workbook(File.Contents("M:\Forecast Sales Projections - Q1.xlsx"), null, true),
#"Location 1_Sheet" = Source{[Item="[COLOR=rgb(61, 142, 185)]Cost Center 1[/COLOR]",Kind="Sheet"]}[Data],
Source = Excel.Workbook(File.Contents("M:\Forecast Sales Projections - Q1.xlsx"), null, true),
#"Location 1_Sheet" = Source{[Item="[COLOR=rgb(61, 142, 185)]Cost Center 2[/COLOR]",Kind="Sheet"]}[Data],
I want VBA to duplicate the query, and then change the Blue text. I assume that #"Location 1_Sheet" does not matter, I append all of the queries at the end so I am not worried about query/sheet names.
Thanks!
Here is the source part of my M code and what I would like to change:
Source = Excel.Workbook(File.Contents("M:\Forecast Sales Projections - Q1.xlsx"), null, true),
#"Location 1_Sheet" = Source{[Item="[COLOR=rgb(61, 142, 185)]Cost Center 1[/COLOR]",Kind="Sheet"]}[Data],
Source = Excel.Workbook(File.Contents("M:\Forecast Sales Projections - Q1.xlsx"), null, true),
#"Location 1_Sheet" = Source{[Item="[COLOR=rgb(61, 142, 185)]Cost Center 2[/COLOR]",Kind="Sheet"]}[Data],
I want VBA to duplicate the query, and then change the Blue text. I assume that #"Location 1_Sheet" does not matter, I append all of the queries at the end so I am not worried about query/sheet names.
Thanks!