+ Reply to Thread
Results 1 to 5 of 5

Events VBA to capture percents

  1. #1
    Registered User
    Join Date
    11-01-2020
    Location
    Lithuania
    MS-Off Ver
    2010
    Posts
    2

    Events VBA to capture percents

    Hi,

    I have "Total amount" in cell "A2", and used amount in cell "B2". Cell "B2" is formatted as number "0,00". So even if I enter 10% in "B2", the value is automatically changed to 0,1. I'd like that Excel VBA would somehow check, if the amount was entered as a percent in "B2". Then, if the check returns TRUE, Excel would multiply percent value by the "Total amount" in cell "A2", and return used amount in cell "B2". For instance, if "A2" has value of 80, then:
    1) If I enter 10 in "B2", Excel would leave 10;
    2) If I enter 10% in "B2", Excel would return value 8 (which is calculated as 80 * 10%) in cell "B2".

    Is it possible to somehow capture, if the amount was entered in percents?
    Last edited by waldux; 11-10-2020 at 02:11 AM.

  2. #2
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Events VBA to capture percents

    if you want to CHECK anything with regard to format of a number, more than likely you can make good use of the format() function:

    https://docs.microsoft.com/en-us/off...r-applications

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,461

    Re: Events VBA to capture percents

    You could use (untested):

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    11-01-2020
    Location
    Lithuania
    MS-Off Ver
    2010
    Posts
    2

    Re: Events VBA to capture percents

    Nope, that doesn't work. Since the cell is formatted as "number", the percentage is automatically changed to the number. So it's not possible to capture "%" symbol with Instr function.
    I made a workaround, not perfect, but still a solution: users are instructed to enter percentages as texts, for instance, ‘10% using apostrophe. In that case it's possible to capture "%" symbol.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,461

    Re: Events VBA to capture percents

    Do you have to format the cell as Number? What happens if it's formatted as General?

+ 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] Capture real time data/DDE capture
    By rajre in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 01-07-2022, 05:14 AM
  2. Replies: 2
    Last Post: 12-30-2018, 07:51 AM
  3. Capture Add-Delete Worksheet Events
    By max57 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-15-2010, 01:33 PM
  4. Macro to capture Sytem Events
    By vikas.bhandari in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-19-2006, 04:57 AM
  5. Percents and Text in one cell - need to add percents only
    By elfmajesty in forum Excel General
    Replies: 3
    Last Post: 03-24-2006, 04:50 AM
  6. How do you capture events?
    By Scott buckwalter in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-12-2005, 01:05 PM
  7. Capture Excel Events from other application
    By George in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-26-2005, 08:07 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