Hi All,
I've come across a road block. The sorting code I have works well only with numerical figures (5/1/2011). How can I make it work with both text ( Early May) and numerical (5/1/2001)figures? for example, here what I have so far:
Private Sub CommandButton2_Click()
Dim wks As Worksheet
Dim lngLastRowMay As Long, lngLastRowJune As Long, lngLastRowJuly As Long, lngLastRowAugust As Long, lngLastRowSeptember As Long, lngLastRowOctober As Long, lngLastRowNovember As Long, lngLastRowDecember As Long, lngActiveRow As Long
Dim intContainer As Integer, intRowIndex As Integer, intColumnIndex As Integer
Dim lLoop As Long, lLoop2 As Long
Dim varWorkflow() As String
Dim strCompanyReport1 As String, strType1 As String, strAnalyst1 As String, strSubmittedToSAs1 As String, strPublicationDate1 As String, strSA1 As String
Dim strCompanyReport2 As String, strType2 As String, strAnalyst2 As String, strSubmittedToSAs2 As String, strPublicationDate2 As String, strSA2 As String
Set wks = Sheet1
lngLastRowMay = wks.Range("B" & Rows.Count).End(xlUp).Row
intContainer = (((lngLastRowMay - 6) - 4) / 8) + 1
ReDim varWorkflow(1 To intContainer, 1 To 6)
intRowIndex = 1
For lngActiveRow = 5 To lngLastRowMay Step 8
If wks.Range("C" & lngActiveRow).Value = vbNullString Then
varWorkflow(intRowIndex, 1) = vbNullString
Else
varWorkflow(intRowIndex, 1) = CStr(wks.Range("C" & lngActiveRow).Value)
End If
If wks.Range("C" & lngActiveRow + 1).Value = vbNullString Then
varWorkflow(intRowIndex, 2) = vbNullString
Else
varWorkflow(intRowIndex, 2) = CStr(wks.Range("C" & lngActiveRow + 1).Value)
End If
If wks.Range("C" & lngActiveRow + 2).Value = vbNullString Then
varWorkflow(intRowIndex, 3) = vbNullString
Else
varWorkflow(intRowIndex, 3) = CStr(wks.Range("C" & lngActiveRow + 2).Value)
End If
If wks.Range("C" & lngActiveRow + 3).Value = vbNullString Then
varWorkflow(intRowIndex, 4) = vbNullString
Else
varWorkflow(intRowIndex, 4) = Format(CDate(wks.Range("C" & lngActiveRow + 3).Value), "yyyy-mm-dd")
End If
If wks.Range("C" & lngActiveRow + 4).Value = vbNullString Then
varWorkflow(intRowIndex, 5) = vbNullString
Else
varWorkflow(intRowIndex, 5) = Format(CDate(wks.Range("C" & lngActiveRow + 4).Value), "yyyy-mm-dd")
End If
If wks.Range("C" & lngActiveRow + 5).Value = vbNullString Then
varWorkflow(intRowIndex, 6) = vbNullString
Else
varWorkflow(intRowIndex, 6) = CStr(wks.Range("C" & lngActiveRow + 5).Value)
End If
intRowIndex = intRowIndex + 1
Next lngActiveRow
Debug.Print "Sorting Dates"
For lLoop = 1 To UBound(varWorkflow, 1)
For lLoop2 = lLoop To UBound(varWorkflow, 1)
If varWorkflow(lLoop2, 5) <> vbNullString Then
If UCase(varWorkflow(lLoop2, 5)) < UCase(varWorkflow(lLoop, 5)) Then
strCompanyReport1 = varWorkflow(lLoop, 1)
strType1 = varWorkflow(lLoop, 2)
strAnalyst1 = varWorkflow(lLoop, 3)
strSubmittedToSAs1 = varWorkflow(lLoop, 4)
strPublicationDate1 = varWorkflow(lLoop, 5)
strSA1 = varWorkflow(lLoop, 6)
strCompanyReport2 = varWorkflow(lLoop2, 1)
strType2 = varWorkflow(lLoop2, 2)
strAnalyst2 = varWorkflow(lLoop2, 3)
strSubmittedToSAs2 = varWorkflow(lLoop2, 4)
strPublicationDate2 = varWorkflow(lLoop2, 5)
strSA2 = varWorkflow(lLoop2, 6)
varWorkflow(lLoop, 1) = strCompanyReport2
varWorkflow(lLoop, 2) = strType2
varWorkflow(lLoop, 3) = strAnalyst2
varWorkflow(lLoop, 4) = strSubmittedToSAs2
varWorkflow(lLoop, 5) = strPublicationDate2
varWorkflow(lLoop, 6) = strSA2
varWorkflow(lLoop2, 1) = strCompanyReport1
varWorkflow(lLoop2, 2) = strType1
varWorkflow(lLoop2, 3) = strAnalyst1
varWorkflow(lLoop2, 4) = strSubmittedToSAs1
varWorkflow(lLoop2, 5) = strPublicationDate1
varWorkflow(lLoop2, 6) = strSA1
End If
End If
Next lLoop2
Next lLoop
Debug.Print "Sorted Dates"
Debug.Print "Inputting New Dates"
intRowIndex = 1
For lngActiveRow = 5 To lngLastRowMay Step 8
wks.Range("C" & lngActiveRow).Value = varWorkflow(intRowIndex, 1)
wks.Range("C" & lngActiveRow + 1).Value = varWorkflow(intRowIndex, 2)
wks.Range("C" & lngActiveRow + 2).Value = varWorkflow(intRowIndex, 3)
wks.Range("C" & lngActiveRow + 3).Value = varWorkflow(intRowIndex, 4)
wks.Range("C" & lngActiveRow + 4).Value = varWorkflow(intRowIndex, 5)
wks.Range("C" & lngActiveRow + 5).Value = varWorkflow(intRowIndex, 6)
intRowIndex = intRowIndex + 1
Next lngActiveRow
Display More
Now I need to also tell excel to sort if the dates entered happen to be, for example, Early May, Mid May or Late May. How can I get the formula to tell excel that if a numerical date is entered the the specified cells ( 5/23/2011) sort date, however if only text is entered (Late May) sort alphabetically by that entry as well.
Can this be done? If so, how? Can you please help me with this? Thank you!