Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 25

Thread: Changes formula to value- wrong number format

  1. #1

    Changes formula to value- wrong number format

    This line changes the formula to a value I need for subsequent operations, however it changes a fraction 1/8 to a date of 8-Jan. I need it to remain 1/8.
    [vba]
    .Range("M4:M" & LRowV).Formula = .Range("M4:M" & LRowV).Value
    [/vba]
    Hopefully a simple fix...

    Thanks.... (sorry for hitting the board so much, trying to finish this one piece)
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I cant reproduce that behaviour Doug, but maybe force it?

    [vba]

    With .Range("M4:M" & LRowV)
    .Formula = .Value
    .NumberFormat = "# ?/?"
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    xld,
    Unfortunately I cannot alter the numberformat first. I will leave this open per your advice, but I am posting a different approach to see if there is another option.
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  4. #4
    Here is my current code.
    This code will not recognize that .Value is a fraction w/ "?/?"
    It will find a value like, .Value = 1
    So If there is another property we can substitue in for "?/?".
    I have tried greater than zero and less than 1, but this fails because there is a formula in the cell.
    [VBA]

    For i = 4 To LRowF
    If Cells(i, "M").Value = "?/?" Then
    Cells(i, "M").NumberFormat = "?/?"
    End If
    Next i
    [/VBA]

    Thanks,

    Doug
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I don't understand, how can .Value be "?/?", that is a numberformat.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    I was under the impression that "?/?" would be a wildcard search for a fractional value.
    I spent a lot of time troubleshooting this y-day/l-night and worked out a solution. A big help was having the Locals window as a Resource- Amazing how much this helped me in needling down- Thanks for teaching me this!

    Note*- If you would like to educate me on this specifically that would be great, but do not spend any of your time writing me any code. I worked out a very ugly solution last night and do not want you to waste any of your time on this currently.

    I still need to grasp a lot of core items and this one shows that!

    Thanks Bob,

    Doug
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Okay, I see what you are trying to do.

    Test the Text property

    [vba]

    If Cells(i, "M").Text Like "*?/?" Then
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    Hi Bob,
    I implemented this, thought it would do the trick. But still hitting a brick wall.
    I have had to change my numberformat for the cells to Fraction - "??/??" to accommodate a few values like 9/10, 11/12.
    Due to this format style when I use the line of code
    [VBA]If Cells(i, "k").Text Like "*?/?" Then[/VBA]
    It does not find any of the fractional values of single values fractions like 1/8 because it is formatted as "??/??"
    Any other suggestions?
    I am telling you, the 80/20 rule is pushing my buttons right now....

    [VBA]
    Sub testk()
    Dim i As Integer
    Dim lrow As Long
    Dim ws As Worksheet
    Set ws = ActiveSheet
    lrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To 20
    If Cells(i, "k").Text Like "*?/?" Then
    Cells(i, "k").NumberFormat = "General"
    'Cells(i, "k").Interior.Color = vbYellow
    End If
    Next i
    End Sub
    [/VBA]
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  9. #9
    Here are three versions of values I need to convert to their proper size format w/ regards to display and numberformat.
    I keep bumping into a particular property of each numerical value which creates undesirable/incorrect values in my size column. All three are to be displayed w/ their fractional sizing.
    If I use the format "?/?" then the second and third display correctly and the first one is truncated down.
    If I use the format "??/??" then all three show the fractional values, but the second and third values display w/ extra space on the right and left hand margins and the third value has big gap between the integer and the fraction.

    Reef Grom Jamaican Sandals Black/Yellow 11/12

    Lucky Bolt Pack 7/8

    32 Lashed Boots 06 Black/Red/Grey 9.5

    Desired:
    11/12
    1/8
    9 1/2

    I have tried different combinations of the numberformat property, .Value, .Text and Like w/out success.

    Thanks

    Doug
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  10. #10
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Does something like this work:
    [VBA]Function GetFractionFormat(strText As String) As String
    Dim intSpace As Integer, intDivisor As Integer
    Dim strNumerator As String, strDenominator As String
    strText = Trim$(strText)
    intSpace = InStr(strText, " ")
    intDivisor = InStr(strText, "/")
    strNumerator = String(Len(Trim$(Mid$(strText, intSpace + 1, intDivisor - intSpace - 1))), "?")
    strDenominator = String(Len(Trim$(Right$(strText, Len(strText) - intDivisor))), "?")
    GetFractionFormat = "# " & strNumerator & "/" & strDenominator
    End Function
    Sub SetFormats()
    Dim rngcell As Range
    For Each rngcell In Selection
    With rngcell
    If Len(.Value) > 0 Then
    .NumberFormat = "# ??/??"
    .NumberFormat = GetFractionFormat(.Text)
    .Formula = .Value
    End If
    End With
    Next rngcell
    End Sub
    [/VBA]

    adjusting the SetFormats routine to test on your data as necessary.

    Regards,
    Rory

  11. #11
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I don't know what is happening here, but I keep making posts and they just disappear. Ah well!

    I said earlier that a format of ??/?? is not Like *?/? whereas it is Like *?/?* - note the difference.

    But I added that I was getting lost as to what you are trying to achieve. You seem to be setting formats, then clearing them, and I am not sure why.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  12. #12
    Rory-
    Yes this works on my test sheet. I will try and incorporate this to my worksheet. I will aprise....

    Bob- If you have time, or when you have time later- maybe I can explain better. Give me a call.... just give me time to get my headset on...
    Btw: I tried the code you gave me, Like "*?/?", but it only had one *, not two like your last post showed... Don't know if this is part of why I did not achieve the results I was hoping for. But I would like to talk to you about this.... Joseph gave me some good pointers that will be relevant.
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  13. #13
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That is exactly why. ? does a single character match so when you use

    *?/? it will match any characters then any single character then a / , then any single character. So these match

    123/1
    a/b
    1/c
    a12/2
    etc.

    but these will not

    123/12
    1/12
    a/12
    a/a/b
    etc.

    So if you were using a format of ??/?? then 11/12 has two character after the / so it will fail that test

    But if you use Like *?/?? a value of 7/8 will fail.

    But you said you have a solution now, so you don't need to bother explaining it.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  14. #14
    Rory-
    Code runs fine in test book- breaks on first record in the Function in my real datasheet
    [vba]
    strNumerator = String(Len(Trim$(Mid$(strText, intSpace + 1, intDivisor - intSpace - 1))), "?")
    [/vba]
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  15. #15
    Rory,
    It is happening on a cell w/ a whole number. This may be the cause.... But I am not clear enough on how to implement on error- especially w/ Functions.
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  16. #16
    Rory,
    I got this to work: I changed this line in the code... Don't ask me how... but w/ Xld showing me some things and your fantastic code.... it worked
    [VBA]
    If .Value <> Int(.Value) And Len(.Value) > 0 Then
    [/VBA]
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  17. #17
    Rory,
    My last solution has some glitches. If I need to do an about face, let me know.
    The code is changing all my sizes to fractional form now, but there are some that need to maintain their decimal numbering.
    This has been accomplished previously by an array in another module- I attempted to incorporate it, but getting lost how to add it in.

    The additional condition that if the Item is in the array that is in either col. F or G then perform your code on these values.
    The array is similar to the other I am using:

    [VBA]For i = 4 To LRowF
    For Each Item In Array("HAT", "FTWR", "BOOT", "BOOTW", "BOOTY", "HWRISR")
    On Error Resume Next
    If (Cells(i, "F").Value = Item Or Cells(i, "G").Value = Item) And _
    Cells(i, "M").Value <> Int(Cells(i, "M").Value) Then[/VBA]

    Current code tinkering w/
    [VBA]
    Sub SetFormats()
    Dim rngcell As Range
    Dim item As Variant
    Dim i As Integer

    For i = 4 To 12000
    For Each item In Array("HAT", "FTWR", "BOOT", "BOOTW", "BOOTY", "HWRISR")

    For Each rngcell In Range("M4:M12000") 'Selection
    With rngcell
    If .Value <> Int(.Value) And Len(.Value) > 0 Then
    .NumberFormat = "# ??/??"
    .NumberFormat = GetFractionFormat(.Text)
    .Formula = .Value
    Exit For
    End If
    Next item
    End With
    Next rngcell
    End Sub
    [/VBA]
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  18. #18
    I have made a little progress, but need the help of VBA Geniuses here... Don't hold back- you know who you are and I really need the help.

    The code is supposed to loop through col. M and correct Mixed Number sizes and Fractional Sizes.
    It is supposed to be limited to correct only the sizes that are listed in the first array.
    It is not being limited as it is editing all non-integer numbers. As I watch in the Locals window, I think it is failing to use the Array of values as criteria to perform its task.

    [VBA]
    Sub SetFormats()
    Dim rngcell As Range
    Dim Item As Variant
    Dim i As Integer

    For i = 4 To 12000
    For Each Item In Array("HAT", "FTWR", "BOOT", "BOOTW", "BOOTY", "HWRISR")
    If (Cells(i, "F").Value = Item Or Cells(i, "G").Value = Item) Then
    For Each rngcell In Range("M4:M12000") 'Selection
    On Error Resume Next
    With rngcell
    If .Value <> Int(.Value) And Len(.Value) > 0 Then
    .NumberFormat = "# ??/??"
    .NumberFormat = GetFractionFormat(.Text)
    .Formula = .Value
    End If
    End With
    Next rngcell 'Exit For
    On Error GoTo 0
    End If
    Next Item
    'Exit For
    Next i
    End Sub
    [/VBA]
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  19. #19
    VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    I changed some stuff but fixed per your request and commented.
    [VBA]
    Sub SetFormats()
    Dim rngcell As Range
    Dim Item As Variant
    Dim i As Integer

    For i = 4 To 12000
    For Each Item In Array("HAT", "FTWR", "BOOT", "BOOTW", "BOOTY", "HWRISR")
    If (Cells(i, "F").Value = Item Or Cells(i, "G").Value = Item) Then
    'this will change all formating in the selection if a match to Item is found
    'For Each rngcell In Range("M4:M12000") 'Selection
    On Error Resume Next
    'changed this to check the cell on the row that matches the array
    With Cells(i, "M")
    If .Value <> Int(.Value) And Len(.Value) > 0 Then
    .NumberFormat = "# ??/??"
    .NumberFormat = GetFractionFormat(.Text)
    .Formula = .Value
    End If
    End With
    'Next rngcell 'Exit For
    On Error GoTo 0
    End If
    Next Item
    'Exit For
    Next i
    End Sub
    [/VBA]

  20. #20
    Rory/Tommy-
    Never Mind- Big Fat Stupid Mistake on my part...
    Last edited by YellowLabPro; 07-31-2007 at 01:18 PM.
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •