+ Reply to Thread
Results 1 to 8 of 8

How can I let the macro determine if the contents of a cell is numeric or text

Hybrid View

  1. #1
    Registered User
    Join Date
    05-19-2012
    Location
    philippines
    MS-Off Ver
    Excel 2007
    Posts
    11

    How can I let the macro determine if the contents of a cell is numeric or text

    Hello everyone,

    i need a help on this one.... I encoded a macro that will simply get the difference of the two column with the use of "DO" and "LOOP" function. But if the cell contains a text data it generates an error and stops the macro. here is my macro:

    Private Sub CommandButton2_Click() 
        On Error Goto okay 
        Dim Cell As Range 
         
        Set Cell = Range("av3") 
        Do Until Cell.Offset(0, -1).Value = "" 
            Cell.Value = Cell.Offset(0, -1).Value - Cell.Offset(0, -5).Value 
            Set Cell = Cell.Offset(1, 0) 
        Loop 
         
    okay: 
        Cell.Value = Cell.Offset(0, -5).Value 
         
         
    End Sub
    How should it appear if i want that the formula will continue until cell.offset(0,-1).value = "" even if along the way there is an error (in this case there is a text data in the cell)?

    Thanks!

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: How can I let the macro determine if the contents of a cell is numeric or text

    try it
    With Range("AV3:AV" & Cells(Rows.Count, "AU").End(xlUp).Row)
        .FormulaR1C1 = "=IFERROR(RC[-1]-RC[-5],RC[-5])"
        .Value = .Value
    End With

  3. #3
    Registered User
    Join Date
    05-19-2012
    Location
    philippines
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: How can I let the macro determine if the contents of a cell is numeric or text

    this works perfectly great!!!! thanks!!!

  4. #4
    Registered User
    Join Date
    05-19-2012
    Location
    philippines
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: How can I let the macro determine if the contents of a cell is numeric or text

    but why if i run this macro using Office 2003 the result is "#NAME?"? do we have any work around for this?

  5. #5
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: How can I let the macro determine if the contents of a cell is numeric or text

    With Range("AV3:AV" & Cells(Rows.Count, "AU").End(xlUp).Row)
    '    .FormulaR1C1 = "=IFERROR(RC[-1]-RC[-5],RC[-5])" ' for Excel 2007(2010)
        .FormulaR1C1 = "=IF(ISERR(RC[-1]-RC[-5]),RC[-5],RC[-1]-RC[-5])" ' for Excel 2003, 2007, 2010, etc. :)
        .Value = .Value
    End With

  6. #6
    Registered User
    Join Date
    05-19-2012
    Location
    philippines
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: How can I let the macro determine if the contents of a cell is numeric or text

    Thanks man! you're the best.. where can i find the explanation for this formula? i want to understand the logic behind this statement... thanks!

  7. #7
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: How can I let the macro determine if the contents of a cell is numeric or text

    Just remove this line
    .Value = .Value
    and you can see very simple formulas in a worksheet

  8. #8
    Registered User
    Join Date
    05-19-2012
    Location
    philippines
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: How can I let the macro determine if the contents of a cell is numeric or text

    now i get it... thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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