Looking for "Select where in" type function

R

randy.buchholz

Hi Group,
I'm trying to work with some log files and have been directed to do this in
Excel. I'm mostly a DB guy and usually only use Excel 2007 for preping data
for a DB load, I need your help please.
The log files are just lines in a text file. In excel I have one column
with a row for each log entry.
I need to perform two processing steps on this data, both using something
like a "Select where in" SQL function.
I have two lists. The first list has "good" items like "Record Inserted".
The Second list is a list of "bad" key words; like "Error" or "Warning.
What I am trying to do step throught the column, processing each row. (I
know how to navigate, but the processing is the issue)
The rules for each row/cell are:
1) If the cell value exactly matches any "Good" value, the row is deleted.
2) If the cell contains any of the words in the "Bad" list, the cell content
is moved (to another sheet?) and the row is deleted from the log.
These rules are applied is this order. Remaining rows are untouched.
Any help would be appreciated,
Thanks
 
D

Don Guillett

Something like this
Sub trythis()
mc = 1 'column A
For i = Cells(Rows.Count, mc).End(xlUp).Row To 2 Step -1
dlr = Sheets("sheet3").Cells(Rows.Count, "a").End(xlUp).Row + 1
Select Case Cells(i, mc)
Case Is = "a", "b"
Rows(i).Delete
Case Is = "c", "d", "e"
Cells(i, mc).Copy Sheet("sheet3").Cells(dlr, "a")
Rows(i).Delete
Case Else
End Select
Next i
Next i
End Sub
 
R

Rick Rothstein

A small modification to your code. Since each line will eventually be
deleted, I would just copy the good items in the list as you come them,
ignore the bad items and delete the entire column when through. I reversed
the order of processing (this keeps the order of copied items in the same
order they appear) and removed the repetitive search for the end of the list
on sheet3 (putting the incrementer in the good item's Case block...

Sub trythis()
mc = 1 'Column A
dlr = Sheets("sheet3").Cells(Rows.Count, "a").End(xlUp).Row + 1
For i = Cells(Rows.Count, mc).End(xlUp).Row To 2 Step -1
Select Case Cells(i, mc)
Case Is = "c", "d", "e" 'Good items
Cells(i, mc).Copy Sheet("sheet3").Cells(dlr, "a")
dlr = dlr + 1
End Select
Next i
Columns(mc).Clear
End Sub
 
R

Rick Rothstein

Of course, after saying I would, I forgot to change the order of processing
in the loop...

Sub trythis()
mc = 1 'Column A
dlr = Sheets("sheet3").Cells(Rows.Count, "a").End(xlUp).Row + 1
For i = 2 To Cells(Rows.Count, mc).End(xlUp).Row
Select Case Cells(i, mc)
Case Is = "c", "d", "e" 'Good items
Cells(i, mc).Copy Sheet("sheet3").Cells(dlr, "a")
dlr = dlr + 1
End Select
Next i
Columns(mc).Clear
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top