+ Reply to Thread
Results 1 to 14 of 14

Sheet name change.

  1. #1
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Thumbs up Sheet name change.

    I am trying to change the name of a sheet to coincide with the contents of a specific cell on a different sheet. In this case the cell will be "A2". The contents of cell A2 is "1002", and this is the problem. I will use this macro over and over and as it is it will always paste the value "1002". How do I make so the macro will copy the contents of the cell at that time and not actually write the value in the macro, but paste what is being copied at the time of running the macro?

    Not much of an explanation , but that is the best I can do.

    This is the code.

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Sheet name change.

    Store the information in a variable rather than copying the cell.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Sheet name change.

    Thanks Andy, That works for that application.

    However I tried that for other copy/paste data and I get an error. I am not sure what I am doing wrong?

    Please Login or Register  to view this content.

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Sheet name change.

    or

    Please Login or Register  to view this content.



  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Sheet name change.

    that code is naming a range not a sheet. Is that what you wanted to be doing?

    Please Login or Register  to view this content.

  6. #6
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Sheet name change.

    Yes, you first reply answered that question. Thankyou.

    But I found that I was have the same problem when coping data from one sheet to another sheet in specified cells, so I tried to use that code. Sorry , I am still only just learning the basics of VBA and I still don't know what you can and can't do.

    Cheers

    Dave

  7. #7
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Sheet name change.

    @Snb, does the last part of your code where is says "Cells(2, 1)" ,referring to the cell "A2"?

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Sheet name change.

    If you want to copy and paste cell content then you can use

    Please Login or Register  to view this content.

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Sheet name change.

    Cells(2, 1) is equivalent to Range("A2") or [A2]

  10. #10
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Sheet name change.

    Can I use that copy from say sheet1 to sheet2, would it look like this?


    Please Login or Register  to view this content.
    Cheers

  11. #11
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Sheet name change.

    @Snb, thanks, thats what I thought.

    Cheers.

  12. #12
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Sheet name change.

    Well ,my code did not work.

  13. #13
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Sheet name change.

    because that is not how you reference sheets and ranges.

    Please Login or Register  to view this content.

  14. #14
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Sheet name change.

    Thanks Andy, that really helps me out. Slowly but surely I am getting understand macros. You have rep points.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1