Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default displaying data from a range

have a bit of a tricky one. I have a range of data that i am using
to produce reports. One of these reports relates to column m. This
range has various dates in each cell. These dates are in the past and
future. What the reports needs to do is identify the first 3 dates in
the range that are over todays date and report how many times these
dates appear in the range, for instance

the range may include


feb 12
feb 20
mar 01
mar 01
april 01
april 01
april 10
may 05
may 05


the results would be mar01 = 2 april 01 = 2 april 10 =1


the reports ignores may 05 as its the fourth furthest date in the
future

I have this codes that works great and displays the dates in a message
box, i would like to know how to adapt this to put the three dates and
three totals into seperate cells

Sub EFG()
Dim oDict As Object
Set oDict = CreateObject("scripting.dictionary")
Dim rng As Range, cell As Range
Dim v As Variant, v1 As Variant
Dim i As Long, j As Long, temp As Variant
Dim msg As String
Set rng = Range(Cells(1, "M"), Cells(1, "M").End(xlDown))
On Error Resume Next
For Each cell In rng
If cell.Value Date Then
If Not oDict.Exists(Format(cell.Value, _
"mm/dd/yyyy")) Then
oDict.Add Format(cell.Value, "mm/dd/yyyy"), _
cell.Value
End If
End If
Next
v = oDict.Keys
v1 = oDict.Items
For i = LBound(v1) To UBound(v1) - 1
For j = i + 1 To UBound(v1)
If v1(i) v1(j) Then
temp = v1(i)
v1(i) = v1(j)
v1(j) = temp
End If
Next
Next
msg = ""
For i = LBound(v1) To LBound(v1) + 2
msg = msg & Format(v1(i), "mm/dd/yyyy") & " " & _
Application.CountIf(rng, v1(i)) & vbNewLine
Next
MsgBox msg

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default displaying data from a range

Sub EFG()
Dim oDict As Object
Set oDict = CreateObject("scripting.dictionary")
Dim rng As Range, cell As Range
Dim v As Variant, v1 As Variant
Dim i As Long, j As Long, temp As Variant
Dim msg As String
Set rng = Range(Cells(1, "M"), Cells(1, "M").End(xlDown))
On Error Resume Next
For Each cell In rng
If cell.Value Date Then
If Not oDict.Exists(Format(cell.Value, _
"mm/dd/yyyy")) Then
oDict.Add Format(cell.Value, "mm/dd/yyyy"), _
cell.Value
End If
End If
Next
v = oDict.Keys
v1 = oDict.Items
For i = LBound(v1) To UBound(v1) - 1
For j = i + 1 To UBound(v1)
If v1(i) v1(j) Then
temp = v1(i)
v1(i) = v1(j)
v1(j) = temp
End If
Next
Next
msg = ""
For i = LBound(v1) To LBound(v1) + 2
cells(i,"S").Value = v1(i)
cells(i,"S").NumberFormat = "mmm dd"
cells(i,"T").Formula = "=Countif(M:M,""=" & v1(i) _
& """)"
Next
End Sub

--
Regards,
Tom Ogilvy

wrote in message
oups.com...
have a bit of a tricky one. I have a range of data that i am using
to produce reports. One of these reports relates to column m. This
range has various dates in each cell. These dates are in the past and
future. What the reports needs to do is identify the first 3 dates in
the range that are over todays date and report how many times these
dates appear in the range, for instance

the range may include


feb 12
feb 20
mar 01
mar 01
april 01
april 01
april 10
may 05
may 05


the results would be mar01 = 2 april 01 = 2 april 10 =1


the reports ignores may 05 as its the fourth furthest date in the
future

I have this codes that works great and displays the dates in a message
box, i would like to know how to adapt this to put the three dates and
three totals into seperate cells

Sub EFG()
Dim oDict As Object
Set oDict = CreateObject("scripting.dictionary")
Dim rng As Range, cell As Range
Dim v As Variant, v1 As Variant
Dim i As Long, j As Long, temp As Variant
Dim msg As String
Set rng = Range(Cells(1, "M"), Cells(1, "M").End(xlDown))
On Error Resume Next
For Each cell In rng
If cell.Value Date Then
If Not oDict.Exists(Format(cell.Value, _
"mm/dd/yyyy")) Then
oDict.Add Format(cell.Value, "mm/dd/yyyy"), _
cell.Value
End If
End If
Next
v = oDict.Keys
v1 = oDict.Items
For i = LBound(v1) To UBound(v1) - 1
For j = i + 1 To UBound(v1)
If v1(i) v1(j) Then
temp = v1(i)
v1(i) = v1(j)
v1(j) = temp
End If
Next
Next
msg = ""
For i = LBound(v1) To LBound(v1) + 2
msg = msg & Format(v1(i), "mm/dd/yyyy") & " " & _
Application.CountIf(rng, v1(i)) & vbNewLine
Next
MsgBox msg

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default displaying data from a range

thanks again tom but its now only showing the first two dates, any
ideas

John

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default displaying data from a range

Here is a fix:

Sub EFG()
Dim oDict As Object
Set oDict = CreateObject("scripting.dictionary")
Dim rng As Range, cell As Range
Dim v As Variant, v1 As Variant
Dim i As Long, j As Long, temp As Variant
Dim msg As String
Set rng = Range(Cells(1, "M"), Cells(1, "M").End(xlDown))
On Error Resume Next
For Each cell In rng
If cell.Value Date Then
If Not oDict.Exists(Format(cell.Value, _
"mm/dd/yyyy")) Then
oDict.Add Format(cell.Value, "mm/dd/yyyy"), _
cell.Value
End If
End If
Next
v = oDict.Keys
v1 = oDict.Items
For i = LBound(v1) To UBound(v1) - 1
For j = i + 1 To UBound(v1)
If v1(i) v1(j) Then
temp = v1(i)
v1(i) = v1(j)
v1(j) = temp
End If
Next
Next
msg = ""
j = 1
For i = LBound(v1) To LBound(v1) + 2
cells(j,"S").Value = v1(i)
cells(j,"S").NumberFormat = "mmm dd"
cells(j,"T").Formula = "=Countif(M:M,""=" & v1(i) _
& """)"
j = j + 1
Next
End Sub


--
Regards,
Tom Ogilvy

wrote in message
oups.com...
thanks again tom but its now only showing the first two dates, any
ideas

John



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying all combinations of a range of numbers Mally Excel Worksheet Functions 5 May 10th 16 07:54 AM
Displaying text during a range of dates RS Excel Worksheet Functions 5 January 2nd 07 03:47 PM
Displaying cell range with Vlookup Danhalawi Excel Discussion (Misc queries) 2 November 9th 06 03:28 PM
Displaying range value when range name is concatenated Barb Reinhardt Excel Discussion (Misc queries) 5 November 6th 06 06:11 PM
Displaying numbers stored in a range??? rpp114 Excel Discussion (Misc queries) 0 May 4th 06 07:37 PM


All times are GMT +1. The time now is 01:12 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"