+ Reply to Thread
Results 1 to 7 of 7

Sheets("Rpt").Copy different results from running in macro than off excel menu??

Hybrid View

tmbo Sheets("Rpt").Copy different... 08-08-2006, 12:36 AM
Guest Re: Sheets("Rpt").Copy... 08-08-2006, 08:15 AM
tmbo reply 08-08-2006, 09:33 PM
Guest Re: Sheets("Rpt").Copy... 08-08-2006, 10:15 PM
tmbo reply 08-08-2006, 10:39 PM
Guest Re: Sheets("Rpt").Copy... 08-09-2006, 08:19 AM
Guest Re: Sheets("Rpt").Copy... 08-09-2006, 08:19 AM
  1. #1
    Registered User
    Join Date
    08-07-2006
    Posts
    5

    Sheets("Rpt").Copy different results from running in macro than off excel menu??

    Hi, thanks in advance for anyone who can help.

    When I run the above command embedded in a macro it does the copy sheet command sucessfully but loses the number format of the original.

    When I use the Excel edit > move or copy sheet to do the same thing it preserves the number format (which is a custom format).

    I really need to preserve the original number formats. Anyone have any ideas?

  2. #2
    Dave Peterson
    Guest

    Re: Sheets("Rpt").Copy different results from running in macro than offexcel menu??

    I couldn't duplicate this in xl2003.

    What version of excel are you using and what's the custom number format?

    tmbo wrote:
    >
    > Hi, thanks in advance for anyone who can help.
    >
    > When I run the above command embedded in a macro it does the copy sheet
    > command sucessfully but loses the number format of the original.
    >
    > When I use the Excel edit > move or copy sheet to do the same thing it
    > preserves the number format (which is a custom format).
    >
    > I really need to preserve the original number formats. Anyone have any
    > ideas?
    >
    > --
    > tmbo
    > ------------------------------------------------------------------------
    > tmbo's Profile: http://www.excelforum.com/member.php...o&userid=37214
    > View this thread: http://www.excelforum.com/showthread...hreadid=569306


    --

    Dave Peterson

  3. #3
    Registered User
    Join Date
    08-07-2006
    Posts
    5

    reply

    Hi Dave,

    Thanks for the reply.

    I am using 2003 and the number format I am using is:

    _(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)

    So if you have a sheet with a custom number format as above and then use

    Edit > move or copy sheet >

    with
    To Book: (New Book)

    and Create a copy ticked

    It will keep the format. If at the same time you record the macro to do that process and then play that macro it will lose the format...very frustrating!!!

    Hope you can help.

    Thanks Tim

  4. #4
    Dave Peterson
    Guest

    Re: Sheets("Rpt").Copy different results from running in macro than offexcel menu??

    I still couldn't replicate it.

    I used this code to test:

    Option Explicit
    Sub testme()

    Dim wks As Worksheet
    Set wks = Worksheets("sheet1")

    With wks
    .Range("a1").NumberFormat _
    = "_(* #,##0_);_(* (#,##0);_(* "" - ""_);_(@_)"
    Debug.Print "Before: " & .Range("A1").NumberFormat
    .Copy
    End With

    Debug.Print "After: " & ActiveSheet.Range("a1").NumberFormat
    End Sub

    And pasting from the immediate window:

    Before: _(* #,##0_);_(* (#,##0);_(* " - "_);_(@_)
    After: _(* #,##0_);_(* (#,##0);_(* " - "_);_(@_)

    And when I used .Move (instead of .Copy), I got this:

    Before: _(* #,##0_);_(* (#,##0);_(* " - "_);_(@_)
    After: _(* #,##0_);_(* (#,##0);_(* " - "_);_(@_)

    I don't know if this has anything to do with your problem, but this formatting
    is the same as my Accounting with 0 decimals and no currency symbol. Is there
    anything special with your accounting format?

    Are you using USA settings?

    What happens if you try the code I used? How about with a brand new workbook?

    (I don't have a guess why it wouldn't work for you.)



    tmbo wrote:
    >
    > Hi Dave,
    >
    > Thanks for the reply.
    >
    > I am using 2003 and the number format I am using is:
    >
    > _(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)
    >
    > So if you have a sheet with a custom number format as above and then
    > use
    >
    > Edit > move or copy sheet >
    >
    > with
    > To Book: (New Book)
    >
    > and Create a copy ticked
    >
    > It will keep the format. If at the same time you record the macro to do
    > that process and then play that macro it will lose the format...very
    > frustrating!!!
    >
    > Hope you can help.
    >
    > Thanks Tim
    >
    > --
    > tmbo
    > ------------------------------------------------------------------------
    > tmbo's Profile: http://www.excelforum.com/member.php...o&userid=37214
    > View this thread: http://www.excelforum.com/showthread...hreadid=569306


    --

    Dave Peterson

  5. #5
    Registered User
    Join Date
    08-07-2006
    Posts
    5

    reply

    Hi Dave,

    To replicate it perhaps create a new number format in your custom list that is not included in the template used to open a new sheet.

    Unfortunately the code didn't work.

    I think the problem with what I am doing is that when the code runs from the macro it opens a new worksheet from a template that doesn't have the format as a custom format.

    I have to post the spreadsheet out to many users so I don't think it is practical to get everyone to change their templates.

    Still it is strange that when I run the same command from the Excel menu it doesn't lose the formatting...can't quite work that one out.

    I wonder if there is some other way I can around it...?


    Cheers

    Tim

  6. #6
    Dave Peterson
    Guest

    Re: Sheets("Rpt").Copy different results from running in macro than offexcel menu??

    I don't have another guess,

    Sorry.

    tmbo wrote:
    >
    > Hi Dave,
    >
    > To replicate it perhaps create a new number format in your custom list
    > that is not included in the template used to open a new sheet.
    >
    > Unfortunately the code didn't work.
    >
    > I think the problem with what I am doing is that when the code runs
    > from the macro it opens a new worksheet from a template that doesn't
    > have the format as a custom format.
    >
    > I have to post the spreadsheet out to many users so I don't think it is
    > practical to get everyone to change their templates.
    >
    > Still it is strange that when I run the same command from the Excel
    > menu it doesn't lose the formatting...can't quite work that one out.
    >
    > I wonder if there is some other way I can around it...?
    >
    > Cheers
    >
    > Tim
    >
    > --
    > tmbo
    > ------------------------------------------------------------------------
    > tmbo's Profile: http://www.excelforum.com/member.php...o&userid=37214
    > View this thread: http://www.excelforum.com/showthread...hreadid=569306


    --

    Dave Peterson

  7. #7
    Dave Peterson
    Guest

    Re: Sheets("Rpt").Copy different results from running in macro than offexcel menu??

    I don't connect through excelforum, so I don't see the attachment. And I don't
    open attachments anyway.

    tmbo wrote:
    >
    > Hi Dave,
    >
    > I attached a spreadsheet with an example.
    >
    > If you run the macro in the this workbook you should see it revert to
    > the minus signs.
    >
    > Cheers
    >
    > Tim
    >
    > --
    > tmbo
    > ------------------------------------------------------------------------
    > tmbo's Profile: http://www.excelforum.com/member.php...o&userid=37214
    > View this thread: http://www.excelforum.com/showthread...hreadid=569306


    --

    Dave Peterson

+ 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