+ Reply to Thread
Results 1 to 7 of 7

Macro to put brackets around negative numbers not working

  1. #1
    Registered User
    Join Date
    06-07-2017
    Location
    Canada
    MS-Off Ver
    Microsoft Office 2016
    Posts
    9

    Post Macro to put brackets around negative numbers not working

    Hi everyone,

    I have been manually formatting each worksheet in this workbook so that negative numbers are in brackets and I'd like to record a macro so that it can automate it through out the worksheet as I have 30 other files that would need this formatting. After recording my actions, it seems that the format doesn't change at all on the new worksheets. Attached to the post is my file and here is my code:

    Please Login or Register  to view this content.
    Thanks!
    Attached Files Attached Files
    Last edited by FinanceGeek94; 06-13-2017 at 12:17 PM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Macro to put brackets around negative numbers not working

    Why struggle with VBA when you can just use a normal format for the cells. i.e.

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    06-07-2017
    Location
    Canada
    MS-Off Ver
    Microsoft Office 2016
    Posts
    9

    Re: Macro to put brackets around negative numbers not working

    I tried to record a macro using normal format, and it still won't work for me :/ Any ideas? It records the macro but it actually does nothing when it's applied.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Macro to put brackets around negative numbers not working

    Hi,

    I can't see why you just can't select all the cells and manually format them with the format I gave you and have done with it.

    However if you must have a macro then simply

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-07-2017
    Location
    Canada
    MS-Off Ver
    Microsoft Office 2016
    Posts
    9

    Re: Macro to put brackets around negative numbers not working

    I got it to work!! Thank you so much! I'm fairly new to Excel outside of the school environment but am working a summer internship where I have time to learn more. You're right, I could have done it manually but doing so for 260 worksheets (10 worksheets for 26 files) would not have been a fun. Thank you for making my life easier and I'm hoping to learn more about vba and macros soon. It's my second week on the job trying out macros!

    My final code:
    Please Login or Register  to view this content.
    Last edited by FinanceGeek94; 06-13-2017 at 12:06 PM.

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Macro to put brackets around negative numbers not working

    OK,

    Well done.

    One final comment. Rarely do you need to use .Select or .Activate stuff. I know that's what the macro recorder captures but that's because it has nothing else to work with. Using .Select & Activate slows down VBA as well. You could safely remove the ws.Activate line of code.

    Please note the forum rule about wrapping code inside code tags when posting code. Click the # symbol so that it aligns neatly making it easier to read, particularly when there are several lines of code.

  7. #7
    Registered User
    Join Date
    06-07-2017
    Location
    Canada
    MS-Off Ver
    Microsoft Office 2016
    Posts
    9

    Re: Macro to put brackets around negative numbers not working

    Alright Richard, your comments are duly noted and I appreciate you following up rapidly to this thread. I have also edited my previous posts to make the coding easier to read.
    Many thanks and cheers!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Negative Numbers in Red Brackets, Positive Numbers in Accounting Format
    By STUARTXL in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-24-2015, 08:29 AM
  2. Brackets for negative numbers
    By pam43 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-16-2014, 01:10 PM
  3. [SOLVED] Formatting numbers to have negative in brackets
    By onroute in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-03-2014, 04:54 PM
  4. [SOLVED] Set negative numbers in brackets as default
    By psychedelic in forum Excel General
    Replies: 4
    Last Post: 11-28-2012, 08:32 PM
  5. [SOLVED] How do I get brackets around negative numbers?
    By Valtam in forum Excel General
    Replies: 9
    Last Post: 02-27-2005, 08:06 PM
  6. Negative Numbers in Brackets - HELP!
    By Hélène in forum Excel General
    Replies: 21
    Last Post: 02-18-2005, 07:06 PM
  7. How do I get negative numbers to show as brackets?
    By mazza in forum Excel General
    Replies: 6
    Last Post: 02-04-2005, 04:06 AM

Tags for this Thread

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