+ Reply to Thread
Results 1 to 7 of 7

VBA: Manipulate only the number within a cell

  1. #1
    Registered User
    Join Date
    02-21-2019
    Location
    Montreal
    MS-Off Ver
    2018
    Posts
    4

    VBA: Manipulate only the number within a cell

    Hello!

    I wanted to know how I can manipulate only the number within a cell using VBA

    For example, if a user writes >=5 in the cell, it should multiply the number by 10,000 and show as >=50000. Similarly =2.5 should show up as =25000.

    I tried

    Set rng = ThisWorkbook.Sheets("Automated Data").Range("B2:B13")

    For Each c In rng
    c.Value = c.Value / 1000

    Next

    I assume I get an error because of the text in it, so I'd like to know how to work around that.

    Thanks in advance!

  2. #2
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: VBA: Manipulate only the number within a cell

    try:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-21-2019
    Location
    Montreal
    MS-Off Ver
    2018
    Posts
    4

    Re: VBA: Manipulate only the number within a cell

    Thanks for the quick response Roel! Unfortunately, that doesn't work.

    FYI, I changed the code to IsNumeric instead of IsNumber since the latter gave an error. Is there something else I'm supposed to include when using IsNumber?

  4. #4
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: VBA: Manipulate only the number within a cell

    I'm sorry I used the worksheetfunction (isnumber) instead of the VBA specific testfunction (IsNumeric) for this.. I simply confused the two..

    you cloud add worksheetfunction.isnumber(c.value) then it will work, but in general use the VBA function in VBA.
    Last edited by Roel Jongman; 02-23-2019 at 03:44 AM.

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA: Manipulate only the number within a cell

    Or extract the numbers.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  6. #6
    Registered User
    Join Date
    02-21-2019
    Location
    Montreal
    MS-Off Ver
    2018
    Posts
    4

    Re: VBA: Manipulate only the number within a cell

    Thanks Roel and bakerman!

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA: Manipulate only the number within a cell

    You're welcome and thanks for rep+.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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] manipulate dropdown when cell value changes
    By juriemagic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-03-2014, 01:15 AM
  2. VBA to manipulate dates based on cell value
    By Buzzter in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-17-2014, 07:07 PM
  3. [SOLVED] Formula to manipulate with cell letters?
    By babapusy in forum Excel Formulas & Functions
    Replies: 18
    Last Post: 02-01-2013, 08:28 AM
  4. manipulate a cell value in excel 2010
    By anuraag1 in forum Excel General
    Replies: 1
    Last Post: 01-29-2013, 04:35 AM
  5. [SOLVED] Manipulate a cell value so that first number is translated to a letter
    By CNE5x in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-24-2012, 04:04 PM
  6. How to manipulate cell index?
    By Gnimgnay in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 12-15-2011, 08:09 PM
  7. How to manipulate current & last values of a cell ?
    By Jgerrety in forum Excel General
    Replies: 10
    Last Post: 03-11-2009, 10:56 PM

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