• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Coding: Please help!

sealion1

Member
Hi all,

I was wondering if somebody could help me code the following in VBA - I know a little bit about VBA, but am struggling with this.

I am looking at a way of searching column B2 in my "Raw Data" tab for keywords that are in my "Keywords" tab. I then want to copy any of the matching rows to my "Dashboard" tab.

I have included a copy of my spreadsheet to this post.

Thanks so much in advance!
 

Attachments

  • Test V1.xlsm
    13.5 KB · Views: 3
Hi all,

I was wondering if somebody could help me code the following in VBA - I know a little bit about VBA, but am struggling with this.

I am looking at a way of searching column B2 in my "Raw Data" tab for keywords that are in my "Keywords" tab. I then want to copy any of the matching rows to my "Dashboard" tab.

I have included a copy of my spreadsheet to this post.

Thanks so much in advance!
Have a look at your workbook and click the button.
 

Attachments

  • Test V1.xlsm
    23.7 KB · Views: 2
Hi Mike,

That works brilliantly - thank you.

In the actual spreadsheet that I need to use at work, the "raw data" is actually drawn from row "AG" - where do I change this in the coding?

Thanks.
 
Hi Mike,

That works brilliantly - thank you.

In the actual spreadsheet that I need to use at work, the "raw data" is actually drawn from row "AG" - where do I change this in the coding?

Thanks.
Hi,

This now looks at column AG

Code:
Sub somesub()
Dim LastRow As Long, c As Range
Dim LastRow1 As Long, LastRow2 As Long
Dim MyRange As Range, ChkRange As Range
Dim Src As Worksheet
Dim Dst As Worksheet
Set Src = Sheets("Raw Data")
Set Dst = Sheets("Dashboard")
LastRow1 = Sheets("Keywords").Cells(Rows.Count, "A").End(xlUp).Row
Set ChkRange = Sheets("Keywords").Range("A2:A" & LastRow1)
LastRow = Src.Cells(Rows.Count, "AG").End(xlUp).Row
Set MyRange = Src.Range("AG2:AG" & LastRow)
For Each c In MyRange
If Not IsError(Application.Match(c.Value, ChkRange, 0)) Then
LastRow2 = Dst.Cells(Rows.Count, "A").End(xlUp).Row + 1
c.EntireRow.Copy Dst.Cells(LastRow2, "A")

End If
Next
End Sub
 
Again - brilliant Mike, thanks!

Last question, the data is column AG is going to have the keyword in, but it could be mixed in with other words, for example;

Warehouse 13, X Lane 1, Roehampton
Unit 88 - 92, X Lane 12, Hammersmith

Will the code above still pick this out or will it bypass it thinking that the data doesn't 100% match?

Thanks.
 
Again - brilliant Mike, thanks!

Last question, the data is column AG is going to have the keyword in, but it could be mixed in with other words, for example;

Warehouse 13, X Lane 1, Roehampton
Unit 88 - 92, X Lane 12, Hammersmith

Will the code above still pick this out or will it bypass it thinking that the data doesn't 100% match?

Thanks.
Hi,

The code now will only copy lines over if it finds the full string. What you want is doable but more complicated because if we search for (say) X lane 1 as a partial string it would fine that in X lane 12. I'm going out right now and if no one has given you a solution I'll work on it later.
 
Thanks for all your help Mike - would really appreciate you taking a look when you get back later if no-one else has found a solution.
 
Thanks for all your help Mike - would really appreciate you taking a look when you get back later if no-one else has found a solution.
Hi,

I've based this code upon these 2 examples.

Warehouse 13, X Lane 1, Roehampton
Unit 88 - 92, X Lane 12, Hammersmith

I have assumed that there will always be a comma or space before/after the string we're looking for.
 

Attachments

  • Test V1.xlsm
    27.1 KB · Views: 8
Back
Top