View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.misc
Jbm Jbm is offline
external usenet poster
 
Posts: 28
Default Sort by cell contents

Using a macro in Excel 2007. I have a cell in P1 with a date in it, and I
need to pull data from G-K that correspond to this date (dates are held in
column G). The code I have looks like this but does not work. I am certain
the line 'If c.Value Like "Range(P1).value" Then' is wrong, but I don't know
how to compare a c.value to a cell value. Thanks for the help.

Sub Test()
RowCount = 1
For Each c In Range("G:G")
If c.Value Like "Range(P1).value" Then
Cells(RowCount, "R").Value = c.Value
Cells(RowCount, "S").Value = c.Offset(0, 1).Value
Cells(RowCount, "T").Value = c.Offset(0, 2).Value
Cells(RowCount, "U").Value = c.Offset(0, 3).Value
Cells(RowCount, "V").Value = c.Offset(0, 4).Value
RowCount = RowCount + 1
End If
Next
End Sub