+ Reply to Thread
Results 1 to 25 of 25

macro to find percentage

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-20-2013
    Location
    Ann Arbor, MI
    MS-Off Ver
    Excel 2010
    Posts
    255

    macro to find percentage

    Hello I have a column with either the words, Late or On Time listed.

    I need to find the percentage of how many entries are Late and how many are on time.

    I can't use a simple formula because every time I run a different macro, it clears the contents on the spreadsheet.

    the workbook is attached. It is on the "Modify Data" sheet.
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    08-08-2005
    Location
    Kansas, USA
    MS-Off Ver
    2016
    Posts
    293

    Re: macro to find percentage

    Why not modify the macro to add the formula after running?

  3. #3
    Forum Contributor
    Join Date
    05-20-2013
    Location
    Ann Arbor, MI
    MS-Off Ver
    Excel 2010
    Posts
    255

    Re: macro to find percentage

    I don't know what the syntax is for formulas in code. that's my problem.
    I guess I should have been more clear

  4. #4
    Forum Contributor
    Join Date
    05-20-2013
    Location
    Ann Arbor, MI
    MS-Off Ver
    Excel 2010
    Posts
    255

    Re: macro to find percentage

    I don't know what the syntax is for formulas in code. that's my problem.
    I guess I should have been more clear

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: macro to find percentage

    I have added some formulae on columns H3-M to the code you have and see if this what you wanted.
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    05-20-2013
    Location
    Ann Arbor, MI
    MS-Off Ver
    Excel 2010
    Posts
    255

    Re: macro to find percentage

    Thank you! why did you comment out this line?

    '.Range("G3:G" & .Range("F" & .Rows.Count).End(xlUp).Row) = .Range("G3:G" & .Range("F" & .Rows.Count).End(xlUp).Row)

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: macro to find percentage

    The attached is a reply to the match code. If there in no match a blank is returned, so the code deletes if a row in column F is blank.
    Attached Files Attached Files
    Last edited by AB33; 07-31-2013 at 12:21 PM.

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: macro to find percentage

    why did I comment out this line? Because If I did not, column G is blank. You can put it back.

  9. #9
    Forum Contributor
    Join Date
    05-20-2013
    Location
    Ann Arbor, MI
    MS-Off Ver
    Excel 2010
    Posts
    255

    Re: macro to find percentage

    I think you attached the same file?

  10. #10
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: macro to find percentage

    Sorry!
    Try again the same attached.

  11. #11
    Forum Contributor
    Join Date
    05-20-2013
    Location
    Ann Arbor, MI
    MS-Off Ver
    Excel 2010
    Posts
    255

    Re: macro to find percentage

    AB33,

    what happened to this: .Cells(1, 4) = "Days Until Claim Resolution"

    it's written, but its not working anymore, and its causing a lot of the code to start on the wrong line.

  12. #12
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: macro to find percentage

    Emil,
    I have adjusted my code ONLY. I did not touch any other code. Run me my code and see what you get.

  13. #13
    Forum Contributor
    Join Date
    05-20-2013
    Location
    Ann Arbor, MI
    MS-Off Ver
    Excel 2010
    Posts
    255

    Re: macro to find percentage

    okay, so this line of code:
    .Columns("F").SpecialCells(4).EntireRow.Delete
    is what is deleting the top row.

  14. #14
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: macro to find percentage

    Change it to

    .Range("F3", Cells(.Rows.Count, "F").End(xlUp)).SpecialCells(4).EntireRow.Delete

  15. #15
    Forum Contributor
    Join Date
    05-20-2013
    Location
    Ann Arbor, MI
    MS-Off Ver
    Excel 2010
    Posts
    255

    Re: macro to find percentage

    okay.

    so this is the sub being used.

    Sub final()
      Dim i&, x, cell As Range
      Application.ScreenUpdating = 0
      
     With Worksheets("Reason Codes")
        x = .Range("a3").CurrentRegion
     End With
     
     Set dic = CreateObject("scripting.dictionary")
     dic.CompareMode = 1
    
     For i = 1 To UBound(x, 1)
    
            dic.Item(Trim$(x(i, 2))) = Trim$(x(i, 1))
     Next
     
     With Worksheets("Modify Data")
     On Error Resume Next
        For Each cell In .Range("E3", .Cells(Rows.Count, "E").End(xlUp))
            If dic.exists(CStr(cell.Value)) Then
                cell.Offset(, 1) = dic.Item(CStr(cell.Value))
            End If
        Next
           .Columns("F").Replace "#N/A", ""
           .Range("F3", Cells(.Rows.Count, "F").End(xlUp)).SpecialCells(4).EntireRow.Delete
     End With
      Application.ScreenUpdating = True
    End Sub
    it is not deleting the items now.

  16. #16
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: macro to find percentage

    Emil,
    There is not need to post the entire code. It does work. See the attached.
    Attached Files Attached Files

  17. #17
    Forum Contributor
    Join Date
    05-20-2013
    Location
    Ann Arbor, MI
    MS-Off Ver
    Excel 2010
    Posts
    255

    Re: macro to find percentage

    okay, so what you're showing me is correct. then go back to 'ClaimsKL' and click 'Modify Data' again and it will not work.

  18. #18
    Forum Contributor
    Join Date
    05-20-2013
    Location
    Ann Arbor, MI
    MS-Off Ver
    Excel 2010
    Posts
    255

    Re: macro to find percentage

    whats the purpose of putting this line twice?
    .Range("F3", Cells(.Rows.Count, "F").End(xlUp)).SpecialCells(4).EntireRow.Delete
           .Range("F3", Cells(.Rows.Count, "F").End(xlUp)).SpecialCells(4).EntireRow.Delete

  19. #19
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: macro to find percentage

    Okay,
    It does not do any harm, but delete the second line.

    What is 'ClaimsKL' sheet to do with my code?
    I have given you two codes and both of them are working and none of them refers to sheet CLAIMSKL.
    The match code compares Worksheets("Reason Codes") and Worksheets("Modify Data").
    I re-run both codes and both work. You have 293 rows in the original data, but when all non match have been delete, you have now 224 rows and the correct formula in H3-I3
    Attached Files Attached Files

  20. #20
    Forum Contributor
    Join Date
    05-20-2013
    Location
    Ann Arbor, MI
    MS-Off Ver
    Excel 2010
    Posts
    255

    Re: macro to find percentage

    Claimskl contains the button Modify Data. and in the sub modifyBTN_click() it calls the sub test. which is the code that you have written.

    and once the button is pressed, it deletes the first row, and it doesn't remove the #N/A or blank entries.

    When you say, "Re-run both codes" how are you running them?

  21. #21
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: macro to find percentage

    One of the code is called Sub test() and the other one is Sub final(). None of these codes are attached to any button, so I could not have run them from buttons. I run them as I always run codes: by going to the module and press F5.

  22. #22
    Forum Contributor
    Join Date
    05-20-2013
    Location
    Ann Arbor, MI
    MS-Off Ver
    Excel 2010
    Posts
    255

    Re: macro to find percentage

    I know they are not ran by buttons. but they are called in a sub which is ran by a button click.
    "call final
    call test"

    A user, who is not me, is going to be using this excel sheet, and they have no idea how to run code, nor understand it, nor do they know what a module is. which is why I have created the button that is supposed to generate everything in the "modify data" spreadsheet with just a click of a button.

    I have been explaining this to you.

  23. #23
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: macro to find percentage

    Emil,
    Okay! I understand, but I can only help you if there is an issue with the code I have supplied you.

  24. #24
    Forum Contributor
    Join Date
    05-20-2013
    Location
    Ann Arbor, MI
    MS-Off Ver
    Excel 2010
    Posts
    255

    Re: macro to find percentage

    the code does not work properly when called through the button click. and it should be operating just the same, should it not?

  25. #25
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: macro to find percentage

    How the code behaves differently If the code is attached to the correct button? As I said, the only reason I can think of is you have lots of codes in your module and there may be a mixing up of attaching the buttons to different codes. You need to re-check all your buttons. I have shown you more than twice the code works( minus your button). I am happy to help with the code itself. I do not know how and why the code does not work when you run it from a button.

+ 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] How do I find the percentage between three numbers?
    By Kaies in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-07-2013, 07:22 AM
  2. Macro to find specific percentage
    By adillard in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-06-2011, 01:39 PM
  3. [SOLVED] Find percentage ???
    By JoAnne in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-12-2005, 01:10 AM
  4. How do I find a percentage?
    By PBarton in forum Excel General
    Replies: 2
    Last Post: 11-27-2005, 06:45 PM
  5. Find percentage Trend
    By Gaurav in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-15-2005, 07:07 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