Do you have both files present in the same folder?Sorry for the later response, I tried the File but it did not open and got an error END DEBUG, I could not really understand it completely, though I must say you have put a lot of efforts but it is still not meeting the requirements..
No, there is no need for both files to have macros. I just put the macros into both so that you could see your options. Both macros work independantly of each other. It's up to you to choose which will work for your needs.I feel there is not a need of Macros in both the Files, I will explain again as I feel that you have been putting a lot of efforts but unfortunately its getting complicated.
Please if you can explain the VBA code it will be convenient incase I need to modify as per the requirements I can do it then...Code:Sub CopySheet() ' Identify variables for use Dim SheetName As String ' define Sheetname as the value in cell A4. A4 is a dropdown list of customer names. SheetName = Range("A4").Value ' Open the customers workbook. The customers workbook must be in the same folder as the Trial workbook. ' Otherwise, "ActiveWorkbook.path needs to be changed. Workbooks.Open Filename:=ActiveWorkbook.Path & "\Customers.xls" ' Copy the desired customer sheet (sheetname taken from cell A4 of the Trial workbook) and place copy ' in the Trial workbook after the "Control" sheet. Sheets(SheetName).Copy After:=Workbooks("Trial.xls").Sheets("Control") ' Rename the copied sheet to reflect the customer's name, followed by " Trial" to show that this sheet is a ' trial balance sheet. ActiveSheet.Name = SheetName & " Trial" ' The active worksheet at the moment is the copied and renamed worksheet. The below code replaces the ' formulas in the range with the values. The range is currently A:S, but can be changed to suit your needs. ' You could use "Cells.formula" and "Cells.value", but this can take a few minutes to process. I narrowed the ' range to A:S to cut out some processing time. ActiveSheet.Range("A:S").Formula = ActiveSheet.Range("A:S").Value ' Close the customers workbook since we no longer need it. Workbooks("Customers.xls").Close ' Make the Control worksheet active since that is where we started. Sheets("Control").Activate ' Display a message that lets the user know that the copying is complete. MsgBox ("Copy complete") End Sub
Last edited by Whizbang; 10-26-2009 at 09:53 AM.
Dear Whizbang,
I am really thankful to you for the explanations but I am not able to use the two files added by you maybe bcos the path is different...
I am felling very guilty that this is taking so long though you have put a lot of effort but unfortunately it is still not working..
AS I am no good in VBA not able to tweak on it at all..
Really sorry for the trouble.
Ok, so the code that needs to change for a customers file in a different folder than the trial file is this:
in your trial workbook, create a hyperlink, in any cell, to the customers file. Then, copy the path in that hyperlink and paste it into the bit of code above.Code:Workbooks.Open Filename:=ActiveWorkbook.Path & "\Customers.xls"
For instance, if your customers file is in C:\Accounts\Customers\Customers.xls, and your trial is in C:\Accounts\Trial\Trial.xls, then your code could have a relative path or a fixed path.
Fixed path:
Relative path:Code:Workbooks.Open Filename:="C:\Accounts\Customers\Customers.xls"
Code:Workbooks.Open Filename:=ActiveWorkbook.Path & "\..\Customers\Customers.xls"
Dear Whizbang,
I am extremely sorry for the long delay as during this time my PC was beyond repair and therefore there was a such a delay..
After I started again there were other issues which hampered...
Anyways thanks a lot for the help..
I am just revising the responses as its really been a long time!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks