Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8486969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:06:04+00:00 2026-06-10T21:06:04+00:00

I have run into an issue, I have a script thanks to several members

  • 0

I have run into an issue, I have a script thanks to several members here has allowed me to import directly from a file into a workbook. With that same script I’ve incorporated the ability to organize by color red on top, and green underneith. I thought I could write the code to make it so that yellow would be in the middle myself, but it doesn’t take into concideration it seems the difference between yellow and red, although I thought I did make that difference noticable though the script.

If someone can look at this and tell me where I am going wrong it would be greatly apprecaited.

This is what I get now for an end result, the yellow is on the bottom of the sheet btw after importing.

enter image description here

The code for some reason isn’t reading right, so attached is also a link to the sheet, with the added file to import.

Zip File

or the files seperate here…

Sheet

CSV

Here is my code:

Option Explicit

Sub Update_POT()

Dim wsPOD As Worksheet
Dim wsPOT As Worksheet
Dim wsPOA As Worksheet
Dim cel As Range
Dim lastrow As Long, fstcell As Long, i As Long, Er As Long, lstCol As Long, lstRow As Long, strFile As String

Set wsPOD = Sheets("PO Data")
Set wsPOT = Sheets("PO Tracking")
Set wsPOA = Sheets("PO Archive")

    With Application
        .ScreenUpdating = False
        .DisplayAlerts = False
        .EnableEvents = False
        .Calculation = xlCalculationManual
    End With

    With wsPOD
        .Columns("A:AB").ClearContents
        .Range("Y1").Formula = "=COUNTIFS('PO Tracking'!$D:$D,$C1,'PO Tracking'!$C:$C,$D1,'PO Tracking'!$F:$F,$G1)"
        .Range("Z1").Formula = "=IF($M1,"""",""Different"")"
        .Range("AA1").Formula = "=IF(ISBLANK($C1),0,1)"
        .Range("AB1").Formula = "=IF($O1,""Full"","""")"
    End With

    strFile = Application.GetOpenFilename("Text Files (*.csv),*.csv", , "Please selec text file...")

    With wsPOD.QueryTables.Add(Connection:="TEXT;" & strFile, Destination:=wsPOD.Range("A1"))
     .TextFileParseType = xlDelimited
     .TextFileCommaDelimiter = True
     .Refresh
    End With


    With wsPOD
    'first bring columns F:G up to match their line
    For Each cel In Intersect(.UsedRange, .UsedRange.Offset(5), .Columns(6))

        If cel = vbNullString And cel.Offset(, -2) <> vbNullString Then
            .Range(cel.Offset(1), cel.Offset(1, 1)).Copy cel
            cel.Offset(1).EntireRow.Delete
        End If
    Next

    'now fil columns A:D to match PO Date and PO#
    For Each cel In Intersect(.UsedRange, .UsedRange.Offset(5), .Columns(1))

        If cel = vbNullString And cel.Offset(, 5) <> vbNullString Then
            .Range(cel.Offset(-1), cel.Offset(-1, 3)).Copy cel
        End If
    Next
        lastrow = wsPOD.Cells(Rows.Count, "J").End(xlUp).Row
        fstcell = wsPOD.Cells(Rows.Count, "N").End(xlUp).Row
        wsPOD.Range("Y1:AB1").Copy wsPOD.Range("M" & fstcell & ":P" & lastrow)
        wsPOD.Range("M:P").Calculate
    End With

        With Intersect(wsPOD.UsedRange, wsPOD.Columns("P"))
        .AutoFilter 1, "<>Full"
        With Intersect(.Offset(2).EntireRow, .Parent.Range("A:P"))
            .EntireRow.Delete
        End With
        .AutoFilter
    End With

    With Intersect(wsPOD.UsedRange, wsPOD.Columns("N"))
        .AutoFilter 1, "<>Different"
        With Intersect(.Offset(2).EntireRow, .Parent.Range("A:P"))
            .EntireRow.Delete
        End With
        .AutoFilter
    End With

    'Final Adjustments before transfering over to PO Tracking.
    With wsPOD
        .AutoFilterMode = False
        lastrow = wsPOD.Cells(Rows.Count, "A").End(xlUp).Row
        Intersect(.UsedRange, .Range("A4:A" & lastrow)).Cut .Range("Q3")
        Intersect(.UsedRange, .Columns("D")).Cut .Range("R1")
        Intersect(.UsedRange, .Columns("C")).Cut .Range("S1")
        Intersect(.UsedRange, .Columns("B")).Cut .Range("T1")
        Intersect(.UsedRange, .Columns("G")).Cut .Range("U1")
        Intersect(.UsedRange, .Columns("F")).Cut .Range("V1")
     End With

    With wsPOD
        wsPOD.Columns("A:P").ClearContents
        lastrow = wsPOD.Cells(Rows.Count, "Q").End(xlUp).Row
        wsPOD.Range("Q3:V" & lastrow).Copy wsPOT.Cells(Rows.Count, "B").End(xlUp).Offset(1)
    End With
    'Format PO Tracking

    With wsPOT
        .Range("Q1:U1").Copy
        lastrow = .Cells(.Rows.Count, "B").End(xlUp).Row
        .Range("V1:X1").Copy .Range("H3:J" & lastrow)
        .Range("N2:O2").Copy .Range("N3:O" & lastrow)
        .Range("P1:V1").Copy
        .Range("B3:H" & lastrow).PasteSpecial xlPasteFormats
        .Range("K3:K" & lastrow).Borders.Weight = xlThin
        lastrow = .Cells(.Rows.Count, "H").End(xlUp).Row
        .Range("H:J").Calculate

        .Sort.SortFields.Clear

    'Sort PO Tracking

    'Sort Reds
        .Sort.SortFields.Add(.Range("J3:J" & lastrow), _
        xlSortOnIcon, xlAscending, , xlSortNormal).SetIcon Icon:=ActiveWorkbook. _
        IconSets(4).Item(1)

        .Sort.SortFields.Add Key:=Range( _
        "J3:J30" & lastrow), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
        xlSortNormal

    'Sort Yellows
        .Sort.SortFields.Add(.Range("I3:I" & lastrow), _
        xlSortOnIcon, xlAscending, , xlSortNormal).SetIcon Icon:=ActiveWorkbook. _
        IconSets(4).Item(2)

        .Sort.SortFields.Add Key:=Range( _
        "I3:I" & lastrow), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
        xlSortNormal

    'Sort Greens
        .Sort.SortFields.Add(.Range("I3:I" & lastrow), _
        xlSortOnIcon, xlAscending, , xlSortNormal).SetIcon Icon:=ActiveWorkbook. _
        IconSets(4).Item(3)

        .Sort.SortFields.Add Key:=Range( _
        "I3:I" & lastrow), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
        xlSortNormal

        With .Sort
            .SetRange wsPOT.Range("B2:K" & lastrow)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    End With


    With wsPOD
        wsPOD.Columns("Q:X").ClearContents
        wsPOD.Cells(1, 25).Value = "=COUNTIFS('PO Tracking'!$D:$D,$C1,'PO Tracking'!$C:$C,$D1,'PO Tracking'!$F:$F,$G1)"
        wsPOD.Cells(1, 27).Value = "=IF(ISBLANK($C1),0,1)"
        wsPOD.Range("Y1:AB1").Copy wsPOD.Range("M5:P5")
    End With

    With Application
        .ScreenUpdating = True
        .DisplayAlerts = True
         .Calculation = xlCalculationAutomatic
    End With

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:06:06+00:00Added an answer on June 10, 2026 at 9:06 pm

    You have to remove the line

        .Sort.SortFields.Add Key:=Range( _
        "I3:I" & lastrow), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
        xlSortNormal
    

    in

        'Sort Yellows
        .Sort.SortFields.Add(.Range("I3:I" & lastrow), _
        xlSortOnIcon, xlAscending, , xlSortNormal).SetIcon Icon:=ActiveWorkbook. _
        IconSets(4).Item(2)
    
        .Sort.SortFields.Add Key:=Range( _
        "I3:I" & lastrow), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
        xlSortNormal
    

    You cannot have have the same duplicate sort conditions for both Yellow and Green in the same column. Remove that line and try again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have run into an issue where an input field within a form I'm
I am creating a Node.js app on Heroku and have run into an issue.
I am creating my first (!) database, and I have run into an issue
I have run into a small issue in my program. I have a class
I have run into a bit of a design issue with my code. I
Trying to solve an issue for someone else and instead have run into my
I have recently run into a particularly sticky issue regarding committing the result of
I have run into an issue when attempting to globalCompositeOperation to mask/blend shapes and
I am writing a CGI script in python 2.5 and I have run into
I have a SQL script that I am working on and I run into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.