+ Reply to Thread
Results 1 to 8 of 8

How to create a Button to convert a range of cells in Excel?

  1. #1
    Registered User
    Join Date
    07-06-2015
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    3

    How to create a Button to convert a range of cells in Excel?

    Hi everyone!

    I am new to this forum and also to Excel's Macros (VBA) itself, but really do need help so any input would be much appreciated.

    I am in the process of creating a spreadsheet that will assist me with my work.

    Within the spreadsheet I have a range of cells, for example: "E3:E100" that contain figures such as "100.00D, 50.00C" and so on. These are "Credits(positive)" and "Debits(negative)". As you will all be aware, by having 'Alphanumeric' characters within the cells the figures within the column will not calculate. I want to create a button on the spreadsheet that will once clicked remove the letter from the end of the cells and add a "-" to the left of the negative values (that initially contained the 'D' at the end).

    Thank you in advance!

  2. #2
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    853

    Re: How to create a Button to convert a range of cells in Excel?

    This will put the Debit and Credit into the columns next to it.

    Please Login or Register  to view this content.

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: How to create a Button to convert a range of cells in Excel?

    You could format the cells with the custom format #.00"C";#.00"D" and then the D/C will show, but the underlying value will be numeric. No conversion will be needed to do arithmetic.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  4. #4
    Registered User
    Join Date
    07-06-2015
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: How to create a Button to convert a range of cells in Excel?

    Quote Originally Posted by ptmuldoon View Post
    This will put the Debit and Credit into the columns next to it.

    Please Login or Register  to view this content.
    Thank you for the prompt response guys! PTMuldoon. The function successfully converts the numbers and places them in the column to the right however, the negative values are showing as positive! How would I remedy this and is there any way to have the function change the figures in the existing cell instead of putting the new values in the cell next to it.

  5. #5
    Registered User
    Join Date
    07-06-2015
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: How to create a Button to convert a range of cells in Excel?

    Quote Originally Posted by mikerickson View Post
    You could format the cells with the custom format #.00"C";#.00"D" and then the D/C will show, but the underlying value will be numeric. No conversion will be needed to do arithmetic.
    Hi Mikerickson. Thank you also for your reply. I have tried entering the format that you suggested and there doesnt seem to be any change! Any ideas what I might be doing wrong?

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,946

    Re: How to create a Button to convert a range of cells in Excel?

    Hi, welcome to the forum

    As you will all be aware, by having 'Alphanumeric' characters within the cells the figures within the column will not calculate.
    Not strictly true,, check the table below...

    A
    B
    1
    10d
    1110
    2
    100d
    2220
    3
    1000d
    4
    20c
    5
    200c
    6
    2000c

    B2=SUMPRODUCT(--(LEFT($A$1:$A$6,LEN($A$1:$A$6)-1)),--(RIGHT($A$1:$A$6,1)="d"))
    C2=SUMPRODUCT(--(LEFT($A$1:$A$6,LEN($A$1:$A$6)-1)),--(RIGHT($A$1:$A$6,1)="c"))
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  7. #7
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    853

    Re: How to create a Button to convert a range of cells in Excel?

    I often like to keep the original data to compare to. but If you want to continue with the Macro route, this is the same code from above just modified to convert it the same column range.

    Please Login or Register  to view this content.

  8. #8
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: How to create a Button to convert a range of cells in Excel?

    Quote Originally Posted by chojin View Post
    Hi Mikerickson. Thank you also for your reply. I have tried entering the format that you suggested and there doesnt seem to be any change! Any ideas what I might be doing wrong?
    Once you've applied that format, put 23 in a cell (don't type a D or a C), it should show 23.00C

    Then put -134 in the cell, it should show 134.00D.


    The reason that the format change did nothing is that the format only effects numbers, your cells currently hold strings.
    I'm suggesting a completed conversion from entering strings (i.e. with the D or C) to entering numbers and having Excel show the D or C, but not have it part of the cell's value.

+ 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. How to create a command button to send specific cells out of an excel sheet..
    By meltelawi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-22-2013, 05:25 PM
  2. [SOLVED] Saving range of cells in a PDF format using a button on excel worksheet
    By jjin in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-13-2013, 12:18 PM
  3. Can Excel create suggestions based on a range of cells?
    By Philanalyst in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-04-2009, 07:50 PM
  4. Need to create a button that can copy cells, create a new sheet and then paste there
    By torontoguy in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-14-2009, 11:26 AM
  5. Use a button to create a table in excel without overwriting cells
    By Carlo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-08-2005, 01:05 PM

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