PC Review


Reply
Thread Tools Rate Thread

copy row if contain keyword

 
 
tracktraining
Guest
Posts: n/a
 
      26th Feb 2009
Hi Everyone,

i am pretty sure this is an easy fix but i can't seem to figure it out. I
am trying to write the following: find the row that the date fall within
certain date and then within that row, look at cell column "E" and find a
keyword, then both conditions are met then copy the entire row into
sheets("Paste_results").

I am unable to get the "find the rows that the date fall within certain
dates" but I can't get the second part. I can't get it though the second if.
My code is below: (please help)

date1 = Me.StartDate.Value
date2 = Me.EndDate.Value
keyword = Me.Product.Value

With Worksheets("Complaint Log")
Set datecompRng = .Range("I2", .Cells(.Rows.Count, "I").End(xlUp))
Set DescripRng = .Range("E2", .Cells(.Rows.Count, "E").End(xlUp))
End With

Sheets("paste_results").Cells.Clear

For Each datecompRng In datecompRng.Cells
If datecompRng >= date1 And datecompRng <= date2 Then
MsgBox "date between"
If Cells(datecompRng, "E").Value = "*keyword*" Then
MsgBox "contain word"
datecompRng.EntireRow.Copy
Sheets("paste_results").Select
Cells(Rows.Count, 1).End(xlUp)(2).Select
Selection.PasteSpecial Paste:=xlAll
'copy the row
'paste the row in sheet reports
End If
End If
Next datecompRng


thank you,
tracktraining

--
Learning
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      27th Feb 2009
I did not test this but I think the modifications should allow it to do what
you want

date1 = Me.StartDate.Value
date2 = Me.EndDate.Value
keyword = Me.Product.Value

With Worksheets("Complaint Log")
Set datecompRng = .Range("I2", .Cells(.Rows.Count, "I").End(xlUp))
Set DescripRng = .Range("E2", .Cells(.Rows.Count, "E").End(xlUp))
End With

Sheets("paste_results").Cells.Clear

For Each dt In datecompRng.Cells
If dt >= date1 And dt <= date2 Then
MsgBox "date between"
If Cells(dt.Row, "E").Value = "*keyword*" Then
MsgBox "contain word"
dt.EntireRow.Copy
Sheets("paste_results").Select
Cells(Rows.Count, 1).End(xlUp)(2).Select
Selection.PasteSpecial Paste:=xlAll
'copy the row
'paste the row in sheet reports
End If
End If
Next datecompRng

"tracktraining" wrote:

> Hi Everyone,
>
> i am pretty sure this is an easy fix but i can't seem to figure it out. I
> am trying to write the following: find the row that the date fall within
> certain date and then within that row, look at cell column "E" and find a
> keyword, then both conditions are met then copy the entire row into
> sheets("Paste_results").
>
> I am unable to get the "find the rows that the date fall within certain
> dates" but I can't get the second part. I can't get it though the second if.
> My code is below: (please help)
>
> date1 = Me.StartDate.Value
> date2 = Me.EndDate.Value
> keyword = Me.Product.Value
>
> With Worksheets("Complaint Log")
> Set datecompRng = .Range("I2", .Cells(.Rows.Count, "I").End(xlUp))
> Set DescripRng = .Range("E2", .Cells(.Rows.Count, "E").End(xlUp))
> End With
>
> Sheets("paste_results").Cells.Clear
>
> For Each datecompRng In datecompRng.Cells
> If datecompRng >= date1 And datecompRng <= date2 Then
> MsgBox "date between"
> If Cells(datecompRng, "E").Value = "*keyword*" Then
> MsgBox "contain word"
> datecompRng.EntireRow.Copy
> Sheets("paste_results").Select
> Cells(Rows.Count, 1).End(xlUp)(2).Select
> Selection.PasteSpecial Paste:=xlAll
> 'copy the row
> 'paste the row in sheet reports
> End If
> End If
> Next datecompRng
>
>
> thank you,
> tracktraining
>
> --
> Learning

 
Reply With Quote
 
tracktraining
Guest
Posts: n/a
 
      27th Feb 2009
your change didn't work.

The keyword is going to be a word or two words (whatever the user decide to
input). And I want to compare the string inside the column E cells to the
keyword. If any of the words inside the cell matches with the keyword(s),
then I want to copy that entire row.

thanks.
--
Learning


"JLGWhiz" wrote:

> I did not test this but I think the modifications should allow it to do what
> you want
>
> date1 = Me.StartDate.Value
> date2 = Me.EndDate.Value
> keyword = Me.Product.Value
>
> With Worksheets("Complaint Log")
> Set datecompRng = .Range("I2", .Cells(.Rows.Count, "I").End(xlUp))
> Set DescripRng = .Range("E2", .Cells(.Rows.Count, "E").End(xlUp))
> End With
>
> Sheets("paste_results").Cells.Clear
>
> For Each dt In datecompRng.Cells
> If dt >= date1 And dt <= date2 Then
> MsgBox "date between"
> If Cells(dt.Row, "E").Value = "*keyword*" Then
> MsgBox "contain word"
> dt.EntireRow.Copy
> Sheets("paste_results").Select
> Cells(Rows.Count, 1).End(xlUp)(2).Select
> Selection.PasteSpecial Paste:=xlAll
> 'copy the row
> 'paste the row in sheet reports
> End If
> End If
> Next datecompRng
>
> "tracktraining" wrote:
>
> > Hi Everyone,
> >
> > i am pretty sure this is an easy fix but i can't seem to figure it out. I
> > am trying to write the following: find the row that the date fall within
> > certain date and then within that row, look at cell column "E" and find a
> > keyword, then both conditions are met then copy the entire row into
> > sheets("Paste_results").
> >
> > I am unable to get the "find the rows that the date fall within certain
> > dates" but I can't get the second part. I can't get it though the second if.
> > My code is below: (please help)
> >
> > date1 = Me.StartDate.Value
> > date2 = Me.EndDate.Value
> > keyword = Me.Product.Value
> >
> > With Worksheets("Complaint Log")
> > Set datecompRng = .Range("I2", .Cells(.Rows.Count, "I").End(xlUp))
> > Set DescripRng = .Range("E2", .Cells(.Rows.Count, "E").End(xlUp))
> > End With
> >
> > Sheets("paste_results").Cells.Clear
> >
> > For Each datecompRng In datecompRng.Cells
> > If datecompRng >= date1 And datecompRng <= date2 Then
> > MsgBox "date between"
> > If Cells(datecompRng, "E").Value = "*keyword*" Then
> > MsgBox "contain word"
> > datecompRng.EntireRow.Copy
> > Sheets("paste_results").Select
> > Cells(Rows.Count, 1).End(xlUp)(2).Select
> > Selection.PasteSpecial Paste:=xlAll
> > 'copy the row
> > 'paste the row in sheet reports
> > End If
> > End If
> > Next datecompRng
> >
> >
> > thank you,
> > tracktraining
> >
> > --
> > Learning

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      28th Feb 2009
If Cells(datecompRng, "E").Value = "*keyword*" Then
could be:

If Cells(datecompRng, "E").Value like "*" & keyword & "*" Then
or
If lcase(Cells(datecompRng, "E").Value) like "*" & lcase(keyword) & "*" Then

or
If instr(1, Cells(datecompRng, "E").Value, keyword, vbtextcompare) > 0 Then



tracktraining wrote:
>
> Hi Everyone,
>
> i am pretty sure this is an easy fix but i can't seem to figure it out. I
> am trying to write the following: find the row that the date fall within
> certain date and then within that row, look at cell column "E" and find a
> keyword, then both conditions are met then copy the entire row into
> sheets("Paste_results").
>
> I am unable to get the "find the rows that the date fall within certain
> dates" but I can't get the second part. I can't get it though the second if.
> My code is below: (please help)
>
> date1 = Me.StartDate.Value
> date2 = Me.EndDate.Value
> keyword = Me.Product.Value
>
> With Worksheets("Complaint Log")
> Set datecompRng = .Range("I2", .Cells(.Rows.Count, "I").End(xlUp))
> Set DescripRng = .Range("E2", .Cells(.Rows.Count, "E").End(xlUp))
> End With
>
> Sheets("paste_results").Cells.Clear
>
> For Each datecompRng In datecompRng.Cells
> If datecompRng >= date1 And datecompRng <= date2 Then
> MsgBox "date between"
> If Cells(datecompRng, "E").Value = "*keyword*" Then
> MsgBox "contain word"
> datecompRng.EntireRow.Copy
> Sheets("paste_results").Select
> Cells(Rows.Count, 1).End(xlUp)(2).Select
> Selection.PasteSpecial Paste:=xlAll
> 'copy the row
> 'paste the row in sheet reports
> End If
> End If
> Next datecompRng
>
> thank you,
> tracktraining
>
> --
> Learning


--

Dave Peterson
 
Reply With Quote
 
tracktraining
Guest
Posts: n/a
 
      3rd Mar 2009
I tried all of your methods and it still doesn't work. If I have nothing in
the Me.product field, then it goes thru the loop. But when I do have
something in the field (i.e. POD), then it doesn't go thru the loop.

please help. thank you!
--
Learning


"tracktraining" wrote:

> Hi Everyone,
>
> i am pretty sure this is an easy fix but i can't seem to figure it out. I
> am trying to write the following: find the row that the date fall within
> certain date and then within that row, look at cell column "E" and find a
> keyword, then both conditions are met then copy the entire row into
> sheets("Paste_results").
>
> I am unable to get the "find the rows that the date fall within certain
> dates" but I can't get the second part. I can't get it though the second if.
> My code is below: (please help)
>
> date1 = Me.StartDate.Value
> date2 = Me.EndDate.Value
> keyword = Me.Product.Value
>
> With Worksheets("Complaint Log")
> Set datecompRng = .Range("I2", .Cells(.Rows.Count, "I").End(xlUp))
> Set DescripRng = .Range("E2", .Cells(.Rows.Count, "E").End(xlUp))
> End With
>
> Sheets("paste_results").Cells.Clear
>
> For Each datecompRng In datecompRng.Cells
> If datecompRng >= date1 And datecompRng <= date2 Then
> MsgBox "date between"
> If Cells(datecompRng, "E").Value = "*keyword*" Then
> MsgBox "contain word"
> datecompRng.EntireRow.Copy
> Sheets("paste_results").Select
> Cells(Rows.Count, 1).End(xlUp)(2).Select
> Selection.PasteSpecial Paste:=xlAll
> 'copy the row
> 'paste the row in sheet reports
> End If
> End If
> Next datecompRng
>
>
> thank you,
> tracktraining
>
> --
> Learning

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      3rd Mar 2009
The first thing I would do is to qualify all the ranges.

Like:
Cells(datecompRng, "E").Value
becomes:
Worksheets("Complaint Log").Cells(datecompRng, "E").Value

Then the next thing I would do is to eliminate some tests to see if I could get
it to work.

'put something in x999 that should work
For Each datecompRng In Worksheets("Complaint Log").range("X999").cells
'drop this check
'If datecompRng >= date1 And datecompRng <= date2 Then
MsgBox "date between"
If lcase(Worksheets("Complaint Log")Cells(datecompRng, "E").Value)
_
= like "*" & lcase(keyword) & "*" Then
MsgBox "contains word"
End If
'End If
Next datecompRng

To see if that works.


tracktraining wrote:
>
> I tried all of your methods and it still doesn't work. If I have nothing in
> the Me.product field, then it goes thru the loop. But when I do have
> something in the field (i.e. POD), then it doesn't go thru the loop.
>
> please help. thank you!
> --
> Learning
>
> "tracktraining" wrote:
>
> > Hi Everyone,
> >
> > i am pretty sure this is an easy fix but i can't seem to figure it out. I
> > am trying to write the following: find the row that the date fall within
> > certain date and then within that row, look at cell column "E" and find a
> > keyword, then both conditions are met then copy the entire row into
> > sheets("Paste_results").
> >
> > I am unable to get the "find the rows that the date fall within certain
> > dates" but I can't get the second part. I can't get it though the second if.
> > My code is below: (please help)
> >
> > date1 = Me.StartDate.Value
> > date2 = Me.EndDate.Value
> > keyword = Me.Product.Value
> >
> > With Worksheets("Complaint Log")
> > Set datecompRng = .Range("I2", .Cells(.Rows.Count, "I").End(xlUp))
> > Set DescripRng = .Range("E2", .Cells(.Rows.Count, "E").End(xlUp))
> > End With
> >
> > Sheets("paste_results").Cells.Clear
> >
> > For Each datecompRng In datecompRng.Cells
> > If datecompRng >= date1 And datecompRng <= date2 Then
> > MsgBox "date between"
> > If Cells(datecompRng, "E").Value = "*keyword*" Then
> > MsgBox "contain word"
> > datecompRng.EntireRow.Copy
> > Sheets("paste_results").Select
> > Cells(Rows.Count, 1).End(xlUp)(2).Select
> > Selection.PasteSpecial Paste:=xlAll
> > 'copy the row
> > 'paste the row in sheet reports
> > End If
> > End If
> > Next datecompRng
> >
> >
> > thank you,
> > tracktraining
> >
> > --
> > Learning


--

Dave Peterson
 
Reply With Quote
 
tracktraining
Guest
Posts: n/a
 
      3rd Mar 2009
Hi Dave,

thanks for helping out. With your hints, the code finally works.

this is what i had to do:

If LCase(Worksheets("Complaint Log").Cells(datecompRng.Row,
DescripRng.Column).Value) Like "*" & LCase(keyword) & "*" Then


thanks again.

- Tracktraining
--
Learning


"Dave Peterson" wrote:

> The first thing I would do is to qualify all the ranges.
>
> Like:
> Cells(datecompRng, "E").Value
> becomes:
> Worksheets("Complaint Log").Cells(datecompRng, "E").Value
>
> Then the next thing I would do is to eliminate some tests to see if I could get
> it to work.
>
> 'put something in x999 that should work
> For Each datecompRng In Worksheets("Complaint Log").range("X999").cells
> 'drop this check
> 'If datecompRng >= date1 And datecompRng <= date2 Then
> MsgBox "date between"
> If lcase(Worksheets("Complaint Log")Cells(datecompRng, "E").Value)
> _
> = like "*" & lcase(keyword) & "*" Then
> MsgBox "contains word"
> End If
> 'End If
> Next datecompRng
>
> To see if that works.
>
>
> tracktraining wrote:
> >
> > I tried all of your methods and it still doesn't work. If I have nothing in
> > the Me.product field, then it goes thru the loop. But when I do have
> > something in the field (i.e. POD), then it doesn't go thru the loop.
> >
> > please help. thank you!
> > --
> > Learning
> >
> > "tracktraining" wrote:
> >
> > > Hi Everyone,
> > >
> > > i am pretty sure this is an easy fix but i can't seem to figure it out. I
> > > am trying to write the following: find the row that the date fall within
> > > certain date and then within that row, look at cell column "E" and find a
> > > keyword, then both conditions are met then copy the entire row into
> > > sheets("Paste_results").
> > >
> > > I am unable to get the "find the rows that the date fall within certain
> > > dates" but I can't get the second part. I can't get it though the second if.
> > > My code is below: (please help)
> > >
> > > date1 = Me.StartDate.Value
> > > date2 = Me.EndDate.Value
> > > keyword = Me.Product.Value
> > >
> > > With Worksheets("Complaint Log")
> > > Set datecompRng = .Range("I2", .Cells(.Rows.Count, "I").End(xlUp))
> > > Set DescripRng = .Range("E2", .Cells(.Rows.Count, "E").End(xlUp))
> > > End With
> > >
> > > Sheets("paste_results").Cells.Clear
> > >
> > > For Each datecompRng In datecompRng.Cells
> > > If datecompRng >= date1 And datecompRng <= date2 Then
> > > MsgBox "date between"
> > > If Cells(datecompRng, "E").Value = "*keyword*" Then
> > > MsgBox "contain word"
> > > datecompRng.EntireRow.Copy
> > > Sheets("paste_results").Select
> > > Cells(Rows.Count, 1).End(xlUp)(2).Select
> > > Selection.PasteSpecial Paste:=xlAll
> > > 'copy the row
> > > 'paste the row in sheet reports
> > > End If
> > > End If
> > > Next datecompRng
> > >
> > >
> > > thank you,
> > > tracktraining
> > >
> > > --
> > > Learning

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      3rd Mar 2009
Sorry about the typo (missing the dot).

But glad you got it working.

tracktraining wrote:
>
> Hi Dave,
>
> thanks for helping out. With your hints, the code finally works.
>
> this is what i had to do:
>
> If LCase(Worksheets("Complaint Log").Cells(datecompRng.Row,
> DescripRng.Column).Value) Like "*" & LCase(keyword) & "*" Then
>
> thanks again.
>
> - Tracktraining
> --
> Learning
>
> "Dave Peterson" wrote:
>
> > The first thing I would do is to qualify all the ranges.
> >
> > Like:
> > Cells(datecompRng, "E").Value
> > becomes:
> > Worksheets("Complaint Log").Cells(datecompRng, "E").Value
> >
> > Then the next thing I would do is to eliminate some tests to see if I could get
> > it to work.
> >
> > 'put something in x999 that should work
> > For Each datecompRng In Worksheets("Complaint Log").range("X999").cells
> > 'drop this check
> > 'If datecompRng >= date1 And datecompRng <= date2 Then
> > MsgBox "date between"
> > If lcase(Worksheets("Complaint Log")Cells(datecompRng, "E").Value)
> > _
> > = like "*" & lcase(keyword) & "*" Then
> > MsgBox "contains word"
> > End If
> > 'End If
> > Next datecompRng
> >
> > To see if that works.
> >
> >
> > tracktraining wrote:
> > >
> > > I tried all of your methods and it still doesn't work. If I have nothing in
> > > the Me.product field, then it goes thru the loop. But when I do have
> > > something in the field (i.e. POD), then it doesn't go thru the loop.
> > >
> > > please help. thank you!
> > > --
> > > Learning
> > >
> > > "tracktraining" wrote:
> > >
> > > > Hi Everyone,
> > > >
> > > > i am pretty sure this is an easy fix but i can't seem to figure it out. I
> > > > am trying to write the following: find the row that the date fall within
> > > > certain date and then within that row, look at cell column "E" and find a
> > > > keyword, then both conditions are met then copy the entire row into
> > > > sheets("Paste_results").
> > > >
> > > > I am unable to get the "find the rows that the date fall within certain
> > > > dates" but I can't get the second part. I can't get it though the second if.
> > > > My code is below: (please help)
> > > >
> > > > date1 = Me.StartDate.Value
> > > > date2 = Me.EndDate.Value
> > > > keyword = Me.Product.Value
> > > >
> > > > With Worksheets("Complaint Log")
> > > > Set datecompRng = .Range("I2", .Cells(.Rows.Count, "I").End(xlUp))
> > > > Set DescripRng = .Range("E2", .Cells(.Rows.Count, "E").End(xlUp))
> > > > End With
> > > >
> > > > Sheets("paste_results").Cells.Clear
> > > >
> > > > For Each datecompRng In datecompRng.Cells
> > > > If datecompRng >= date1 And datecompRng <= date2 Then
> > > > MsgBox "date between"
> > > > If Cells(datecompRng, "E").Value = "*keyword*" Then
> > > > MsgBox "contain word"
> > > > datecompRng.EntireRow.Copy
> > > > Sheets("paste_results").Select
> > > > Cells(Rows.Count, 1).End(xlUp)(2).Select
> > > > Selection.PasteSpecial Paste:=xlAll
> > > > 'copy the row
> > > > 'paste the row in sheet reports
> > > > End If
> > > > End If
> > > > Next datecompRng
> > > >
> > > >
> > > > thank you,
> > > > tracktraining
> > > >
> > > > --
> > > > Learning

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I remove lines of data above a keyword and below a keyword in a text file Quentin Microsoft VB .NET 1 25th Apr 2007 04:15 PM
How do I remove lines of data above a keyword and below a keyword in a text file Quentin Microsoft VB .NET 0 25th Apr 2007 02:25 PM
Can we use join keyword without using INNER keyword explicitly in. =?Utf-8?B?Uy5TUklLQU5USCxHVURJV0FEQSxBUCxJTkRJQQ== Microsoft Access Queries 1 20th Apr 2005 02:07 PM
Difference between C#'s "new" keyword and VB.NET's "shadows" keyword Dot net work Microsoft C# .NET 8 29th Aug 2004 11:00 AM
Provider keyword in connection string not a valid keyword J. Muenchbourg Microsoft Dot NET 1 18th Mar 2004 09:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:22 AM.