View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
RaY RaY is offline
external usenet poster
 
Posts: 164
Default Find a Value then delete cells before and after

Thanks for the reply. But it's deleting the whole column of data. When the
macro is done the range of times should be from 21:39:02 to 22:01:00 with
each second being present (these times only apply to the first data set).
Right now, everything is removed. Also, I need it to match the K6 and last
values and remove the cells above and below that range from columns A through
E. For example, if the K6 Time is found in cell B1500, then remove all cells
from A6:E1499 and shift the cells up so the Matched K6 value appears in B6.
Then Match the last time found in column K and delete all the cells that
occur after it in columns A:E.

"Bernie Deitrick" wrote:

Ray,

I've assumed that you have true times, not strings....

Sub ClearTimes()
Dim myC As Range
Dim T1 As Date
Dim T2 As Date
T1 = Range("K6").Value
T2 = Cells(Rows.Count, "K").End(xlUp).Value
For Each myC In Intersect(Range("B:B"), ActiveSheet.UsedRange)
If myC.Value < T1 Or myC.Value T2 Then myC.ClearContents
Next myC
End Sub

HTH,
Bernie
MS Excel MVP



"Ray" wrote in message
...
I've searched through most of the strings in the forum, but I cannot find
the
exact help I need. What I need my code to do is use a value that's found
in
cell K6 (which is a time in format h:mm:ss, and will change) and find the
same time value in column B. Then delete all the data that occurs before
that value. I do not want to delete the rows, just the cells. I use the
code,
FinalRow = Cells(Rows.Count, "K").End(xlUp).Row
To find the last time value in column K. I want to use the time value
that
occurs at the end of column K to find the same value in Column B. Only
this
time I want to delete all the data that occurs after that value. Again,
the
cells, not the entire row.

Thankd for your help.