Results 1 to 7 of 7

Macro shows incorrect result

Threaded View

fsalas2006 Macro shows incorrect result 01-24-2014, 07:23 PM
alansidman Re: Report Macro Help 01-24-2014, 07:38 PM
jmac1947 Re: Report Macro Help 01-24-2014, 09:28 PM
jmac1947 Re: Macro shows incorrect... 01-24-2014, 09:27 PM
jmac1947 Re: Macro shows incorrect... 01-24-2014, 09:51 PM
fsalas2006 Re: Macro shows incorrect... 01-26-2014, 06:13 PM
jmac1947 Re: Macro shows incorrect... 01-26-2014, 09:22 PM
  1. #1
    Registered User
    Join Date
    11-10-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    4

    Question Macro shows incorrect result

    Good Afternoon everyone,

    I'm trying to figure this code to fix the following issue. So this Excel macro has 3 sheets (Old, New, and Results), it works by adding an old report to the "Old sheet" and adding
    a new report to "New Sheet". When I run the macro it shows me New orders, Revised Orders, or cancelled on the "Results sheet" and is color coded however I came across an error. If you look at order # 90946 on the second row it shows that is a New order. It's supposed to be revised or "Version" (Yellow) because the version changed from 1 to 2 based on the Old sheet and New Sheet. If you look at order # 99047 on the Results tab you know that it's correct because it went from version 8 to 9. I don't know why order 90946 shows that is New, it's supposed to be a version change from 1 to 2.

    I've attached the excel macro and VBA code is below. Please and thank you.


    VBA Code:

    Sub OpsReport()
    '
    ' Attempt2Ops Macro
    '
    '
        Sheets("Old").Select
        Columns("A:A").Select
        Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    ' Adding First, creating unique ID
     
     Dim tst As Integer
     Dim OrderNum As String
     Dim UniqueId As Integer
     ' Find Order Number
        tst = 2
        Do While Cells(1, tst).Value <> "Order #"
            tst = tst + 1
            OrderNum = tst
        Loop
    ' Find first blank column to create a unique Id
        tst = 2
        Do While Cells(1, tst).Value <> ""
            tst = tst + 1
            UniqueId = tst
        Loop
    ' Print values
        Cells(1, UniqueId).Value = "UniqueID"
        f = 2
        Do While Cells(f, 2).Value <> ""
            Cells(f, 1).Value = "First"
            Cells(f, UniqueId).Value = "=R[0]C" & OrderNum & "&R[0]C" & (OrderNum + 1)
            f = f + 1
        Loop
        
        Sheets("New").Select
        Columns("A:A").Select
        Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    ' Loop until blank row found
     ' Find Order Number
        tst = 2
        Do While Cells(1, tst).Value <> "Order #"
            tst = tst + 1
            OrderNum = tst
        Loop
    ' Print values
        Cells(1, UniqueId).Value = "UniqueID"
        s = 2
        Do While Cells(s, 2).Value <> ""
            Cells(s, 1).Value = "Second"
            Cells(s, UniqueId).Value = "=R[0]C" & OrderNum & "&R[0]C" & (OrderNum + 1)
            s = s + 1
        Loop
    ' copy all sheets into Results
        Sheets("Old").Select
        Range("a2", Cells(f, UniqueId)).Copy
                Sheets("Results").Cells(Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial xlPasteValues
        Sheets("New").Select
        Range("a2", Cells(s, UniqueId)).Copy
                Sheets("Results").Cells(Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial xlPasteValues
    
    ' Add in header info
        Sheets("Results").Select
        Rows("1:1").Select
        Application.CutCopyMode = False
        Selection.Delete Shift:=xlUp
        Sheets("Old").Select
        Rows("1:1").Select
        Selection.Copy
        Sheets("Results").Select
        Rows("1:1").Select
        Selection.Insert Shift:=xlDown
    
    ' Clean up added information
        Sheets("New").Select
        Columns("A:A").Select
        Selection.Delete Shift:=xlToLeft
        Columns("I:I").Select
        Selection.Delete Shift:=xlToLeft
        Sheets("Old").Select
        Columns("A:A").Select
        Selection.Delete Shift:=xlToLeft
        Columns("I:I").Select
        Selection.Delete Shift:=xlToLeft
    
    ' Set conditional formatting
        Sheets("Results").Select
        Columns("J:J").Select
        Cells.FormatConditions.Delete
        Columns("J:J").Select
        Selection.FormatConditions.AddUniqueValues
        Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        Selection.FormatConditions(1).DupeUnique = xlDuplicate
        With Selection.FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .ColorIndex = 6
        End With
        Selection.FormatConditions(1).StopIfTrue = False
    
      ' Filter and Clear duplicates
        Range("J2", Range("J65536").End(xlUp)).Select
        ActiveSheet.Range("J2", Range("J65536").End(xlUp)).AutoFilter Field:=1, Criteria1:=RGB(252, 243, 5), Operator:=xlFilterCellColor
        Selection.EntireRow.Delete
    
        ActiveWorkbook.Worksheets("Results").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Results").Sort.SortFields.Add Key:=Range("C2", Range("C65536").End(xlUp)) _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets("Results").Sort.SortFields.Add Key:=Range("D2", Range("D65536").End(xlUp)) _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Results").Sort
            .SetRange Range("A1", Range("J65536").End(xlUp))
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    
        ' Loop until blank row found
        n = 2
        Do While Cells(n, 2).Value <> ""
            Cells(n, 11).Value = "=IF(RC3<>R[-1]C3,IF(RC3<>R[1]C3,""New or Old"",""Dup""),""Dup"")"
            n = n + 1
        Loop
        
        ' Loop until blank row found
        c = 2
        Do While Cells(c, 2).Value <> ""
            Cells(c, 12).Value = "=IF(RC[-1]=""New or Old"",IF(RC[-11]=""First"",""Cancelled"",""New""),""Version"")"
            c = c + 1
        Loop
    
    ' Coding Rows
        Columns("L:L").Select
        Selection.FormatConditions.Add Type:=xlTextString, String:="New", _
            TextOperator:=xlContains
        Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        With Selection.FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .ColorIndex = 4
        End With
        
        Selection.FormatConditions(1).StopIfTrue = False
        Columns("L:L").Select
        Selection.FormatConditions.Add Type:=xlTextString, String:="Cancelled", _
            TextOperator:=xlContains
        Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        With Selection.FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .ColorIndex = 3
        End With
        
        Selection.FormatConditions(1).StopIfTrue = False
        Columns("L:L").Select
        Selection.FormatConditions.Add Type:=xlTextString, String:="Version", _
            TextOperator:=xlContains
        Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        With Selection.FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .ColorIndex = 6
        End With
    
    ' Hide Extra Columns
        Selection.FormatConditions(1).StopIfTrue = False
        Columns("J:J").Select
        Selection.EntireColumn.Hidden = True
        Columns("K:K").Select
        Selection.EntireColumn.Hidden = True
        Columns("A:A").Select
        Selection.EntireColumn.Hidden = True
    End Sub
    Attached Files Attached Files
    Last edited by fsalas2006; 01-24-2014 at 08:00 PM. Reason: I had to add proper formatting for code

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro to take a report
    By vinayjan in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-03-2013, 07:20 AM
  2. Macro to Automate Report by Case Number and Product Type (Macro Recorder Fail)
    By maxutility in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-17-2012, 10:39 PM
  3. Change source data Macro (macro) in report template
    By andygeb in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-14-2010, 11:14 PM
  4. Report macro
    By nightcrawler-jay in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-14-2010, 01:37 PM
  5. A report macro
    By Jocke in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 04-20-2005, 09:06 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