Hello all,
I have an excel file that gets populated every month and resaved based on the current month/year. I need to routinely copy a range of data from the previous month's file into the current month's file. Within the copy range there are some formulas that use vlookups into another spreadsheet in the workbook. The problem I have is that I don't want the data to be linked to the previous month's file, which happens when I copy the formula. I tried to build a series of ranges to exclude the formulas, but I can't get the data to paste (can't paste multiple selections error) into the new spreadsheet.
One way I found around this was to copy all the data/formulas over. Then I can do a search and replace within the formulas and replace all instances of "[Prevmonth.xls]Products" with "Products", which is the worksheet the vlookup is linked to. The problem I have is that I can't get the search/replace to work within the VBA code.
I set a variable, replacewrd, equal to the string I want replaced.
After the code finished, none of the replacements were made. I hit CTRL-H to bring up the search/replace menu and the fields were populated with the text I wanted to change to and from. I hit Replace All and then all the replacements were made. I want to avoid this last step somehow.
Any help would be greatly appreciated.
Thanks, Darv
I have an excel file that gets populated every month and resaved based on the current month/year. I need to routinely copy a range of data from the previous month's file into the current month's file. Within the copy range there are some formulas that use vlookups into another spreadsheet in the workbook. The problem I have is that I don't want the data to be linked to the previous month's file, which happens when I copy the formula. I tried to build a series of ranges to exclude the formulas, but I can't get the data to paste (can't paste multiple selections error) into the new spreadsheet.
One way I found around this was to copy all the data/formulas over. Then I can do a search and replace within the formulas and replace all instances of "[Prevmonth.xls]Products" with "Products", which is the worksheet the vlookup is linked to. The problem I have is that I can't get the search/replace to work within the VBA code.
I set a variable, replacewrd, equal to the string I want replaced.
Code:
Dim replacewrd As String
replacewrd = CStr("[" + pmonth + " " + s2name + "]" + "Products")
Cells.Replace What:=replacewrd, _
Replacement:="Products", LookAt:=xlPart, SearchOrder:=xlByRows, _
MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
After the code finished, none of the replacements were made. I hit CTRL-H to bring up the search/replace menu and the fields were populated with the text I wanted to change to and from. I hit Replace All and then all the replacements were made. I want to avoid this last step somehow.
Any help would be greatly appreciated.
Thanks, Darv