+ Reply to Thread
Results 1 to 16 of 16

Code to correct errors in cell values

  1. #1
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,171

    Code to correct errors in cell values

    Hello everyone
    I have this code which is to convert certain columns into the format required. As the cells contain errors maybe that is why I am not able to convert the columns into the required format. Can anyone please suggest what to do and how to get the expected result with the help of a code.
    Attached Files Attached Files
    Last edited by RAJESH SHAH; 03-03-2023 at 08:13 AM. Reason: #Solved by Marc L

  2. #2
    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
    47,997

    Re: Code to correct errors in cell values

    The values in column K are Text so you won't be able to apply a numeric format.

    You need to reformat the cells as General and then Copy and Paste Special | Values to convert to numbers.
    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


  3. #3
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,171

    Re: Code to correct errors in cell values

    TMS. I am selecting the first cell and then the whole column, In the side there is a box where I select convert to number and get the format. But that is how it is done manually. Is it not possible to do the same with the help of a code.?

  4. #4
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,171

    Re: Code to correct errors in cell values

    As the Rate% in another sheet is 18 and when I use a formula in the code to join Rate% then the vlookup function will display #NA as this sheet is showing 18.00. The amounts too will show an error when I use a sumifs formula to match the amounts/

  5. #5
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,171

    Re: Code to correct errors in cell values

    If i type, in an empty column in the sheet as =NUMBERVALUE and give the cell reference and enter I will get the number format. For that I will have to create a temp file for each row and then replace the column with the temp file. How to write the code, you people are the experts.

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hello, try this !


    According to your initial post a single VBA codeline as a beginner starter :

    Sheet59.Range("K5", Sheet59.[K4].End(xlDown)).NumberFormat = "General"

    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  7. #7
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,171

    Re: Hello, try this !

    Marc L. After running your code, the display is the same as it was before.. I need to get the number without decimal and without any error and decimal of column K. All other columns with 2 decimals without any errors.

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Code to correct errors in cell values


    ( removed )

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Re: Code to correct errors in cell values


    'Cause you forgot to well read & follow post #2 !
    So according to your attachment a VBA demonstration as a very beginner starter :

    PHP Code: 
    Sub Demo4Noob()
        
    With Sheet59.Range("K5"Sheet59.[K4].End(xlDown))
            .
    NumberFormat "General"
            
    .Formula = .Value
        End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  10. #10
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,171

    Re: Code to correct errors in cell values

    Yes. This is what I wanted. Thanks Marc L.
    Is it possible to add the other columns in this code itself to get the number format for all required columns or should I create individual code for each column.

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Code to correct errors in cell values


    For all consecutive text columns to convert to General number format just obviously change the starting cell address of the End property.

    As a reminder such VBA code is totally useless if rather than importing data with foot an appropriate import protocol is used …

  12. #12
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,171

    Re: Code to correct errors in cell values

    Got all the columns as expected.
    I have replaced the code with the sheet name as I have to do the same with another 9 sheets with the same columns and formats in the same workbook.
    Please Login or Register  to view this content.
    Thanks Marc L. You people are the best.

  13. #13
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Code to correct errors in cell values


    Thanks for the rep' !

    You have made an error when modifying the cell address as I very not wrote the cells addresses …

  14. #14
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,171

    Re: Code to correct errors in cell values

    What error..? Oh Yeah. column K I needed in general format. But, Finally I got the result as expected. I will try and correct it.
    Last edited by RAJESH SHAH; 03-03-2023 at 08:20 AM.

  15. #15
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Code to correct errors in cell values


    As I wrote « the starting cell address » so obviously an unique cell address and not cells addresses …

  16. #16
    Forum Contributor
    Join Date
    11-25-2021
    Location
    INDIA
    MS-Off Ver
    2007
    Posts
    2,171

    Re: Code to correct errors in cell values

    Your code gave me the idea to write the cell addrsses. Thanks man.

+ 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. Cant Figure Out How To Detect Which Cells Have Type Mismatch Errors & Correct Them
    By Genus Max in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-22-2020, 01:04 PM
  2. DIY Spell Check Table To Correct Data Errors using VBA
    By edneal2 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-15-2017, 09:13 AM
  3. Check for errors and correct them based on specific logic
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-08-2016, 12:33 PM
  4. Whats the correct VBA way to handle errors in a complex VBA Spreadsheets
    By nytrex in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-14-2013, 03:24 AM
  5. Fix Needed for Code to Send Correct Data to Correct Sheets
    By swordswinger710 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-04-2012, 03:53 PM
  6. VBA code gets 99% of values correct
    By nzgreven in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-05-2008, 12:31 AM
  7. I need help writing a macro that will correct typing errors?
    By notthemacroman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-26-2006, 08:46 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