+ Reply to Thread
Results 1 to 8 of 8

VBA for dividing values in range if greater than x

  1. #1
    Registered User
    Join Date
    06-12-2015
    Location
    Wolverhampton, England
    MS-Off Ver
    2007
    Posts
    19

    VBA for dividing values in range if greater than x

    Hi all.

    I'm searching for a VBA that looks for values in a range that are greater than a given value, and if found, divides them by 60. I have one that replaces zero's with blank as follows:


    Please Login or Register  to view this content.
    As such, I was imagining that the following code would work:

    Please Login or Register  to view this content.
    Now the experts amongst you will already know that doesn't work. Please help the people in the class not noted as 'gifted and talented' to understand why!


    Thanks in anticipation,

    Frustrated James
    Last edited by JBeaucaire; 10-01-2015 at 10:28 AM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA for dividing values in range if greater than x

    It sure looks like it should work. I guess I'm not an expert.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    06-12-2015
    Location
    Wolverhampton, England
    MS-Off Ver
    2007
    Posts
    19

    Re: VBA for dividing values in range if greater than x

    AlphaFrog - if nothing else you have made me laugh!

  4. #4
    Forum Contributor
    Join Date
    08-07-2015
    Location
    AB, Canada
    MS-Off Ver
    Excel 2013 x64
    Posts
    132

    Re: VBA for dividing values in range if greater than x

    Quote Originally Posted by James Swallow View Post
    Now the experts amongst you will already know that doesn't work.
    I just tried it out on a set of sample data. Worked fine for me...

    How are the results different from what you were expecting?

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA for dividing values in range if greater than x

    The syntax of your code is fine. Are you trying to do something with time values and not getting the desired result? If yes, please expand.

    The code may throw an error if you have any values in the range that are formula error values.

  6. #6
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: VBA for dividing values in range if greater than x

    Yeah, I would guess the rng values in the range aren't numbers, like maybe they are text strings or something?
    I'm interested in starting a career working with VBA, if anyone knows of any opportunities!

  7. #7
    Forum Contributor
    Join Date
    08-07-2015
    Location
    AB, Canada
    MS-Off Ver
    Excel 2013 x64
    Posts
    132

    Re: VBA for dividing values in range if greater than x

    Quote Originally Posted by ThirdFret View Post
    Worked fine for me...
    Wait! I broke it!

    It looks like it doesn't work when there are text values included in the range A1:AK25.

    Just add "On Error Resume Next" at the beginning of the macro and it'll happily skip those pesky text-filled cells.

    Please Login or Register  to view this content.
    Hope that helps!
    Last edited by ThirdFret; 10-01-2015 at 10:55 AM.

  8. #8
    Registered User
    Join Date
    06-12-2015
    Location
    Wolverhampton, England
    MS-Off Ver
    2007
    Posts
    19

    Re: VBA for dividing values in range if greater than x

    Sorry for the delay everyone. I'm doing this between work.

    ThirdFret you're a genius. That did the trick. Kind of my balls up really as if I had just set the range from C2 I would have avoided any text cells.

    Thanks all. I'm really gaining in experience thanks to the help I get on this forum.

    Until next time!

+ 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. Replies: 1
    Last Post: 07-30-2015, 02:55 PM
  2. [SOLVED] find value which is greater than in a range of cells and return the greater value
    By green369 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-11-2015, 02:46 AM
  3. Dividing one Named Range by Another
    By CubsPhan in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-15-2014, 10:39 PM
  4. [SOLVED] count values greater 2 or greater in a column.
    By ammartino44 in forum Excel General
    Replies: 3
    Last Post: 09-16-2014, 07:05 PM
  5. Replies: 2
    Last Post: 06-27-2012, 10:23 AM
  6. Sum cells in range with values greater than 2
    By henneman in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-20-2010, 02:35 PM
  7. Dividing numbers by time values
    By JamesPH in forum Excel General
    Replies: 2
    Last Post: 06-28-2006, 10:40 AM

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