[SOLVED] VBA: Rename Worksheet based on cell value in another Workbook

  • Hello,


    I'm identifying a target file and then copying a tab from that into the workbook. This works fine.


    I then want to rename that tab according to a cell value in the target file and this is where I am failing. Hopefully it's an easy/obvious syntax or similar problem as I haven't touch VB for years.


    Thanks for your help - this is what I have and I get an error on the last line:


  • Re: VBA: Rename Worksheet based on cell value in another Workbook


    Try


    Reading your code I assume that you want the sheet called DATA copied from the Target file to Master dB.xlsm then rename the sheet you copied called DATA to the value in C6 in the Target File from the sheet called inputs general.
    Try as good practice to reference your sheets - there would be a conflict here that you have an open workbook (Targetfile) as the active file so when you try to rename the sheet DATA it would try to rename the workbook you opened. It makes it easier to read and maintain the code.
    I also changed the file to open to allow you to select both xls and xlsx files as well (and xlsm) - you can change that back if you want to only select xls files

    Regards
    [SIZE=3]Anthony
    [/SIZE]&WCF_AMPERSAND[SIZE=3]
    [/SIZE]&WCF_AMPERSAND&WCF_AMPERSAND&WCF_AMPERSAND[SIZE=2]You have your way. I have my way. As for the right way, the correct way, and the only way, it does not exist.[/SIZE]




  • Re: VBA: Rename Worksheet based on cell value in another Workbook


    Nice one Anthony!


    You assumed right and the revised code works nicely - thank you very much!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!