Solved

Compare & Copy Specific Text Values

Posted on 2014-04-29
8
150 Views
Last Modified: 2014-04-30
I have the following code that I would like to add critieria too, however I can not get it work based on what I added

Sub aaa()
  Dim ChkSH As Worksheet
  Set ChkSH = Sheets("LM")

    ce = "Local Market"
   
Sheets("Variance").Activate
  For Each ce In Range("a4:a" & Cells(Rows.Count, 1).End(xlUp).Row)
    Set findit = ChkSH.Range("a4:a3000").Find(what:=ce, LookIn:=xlValues, _
    LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False)

    If findit Is Nothing Then Range("A" & ce.Row).Copy _
        ChkSH.Range("a65000").End(xlUp).Offset(1, 0)

  Next ce
End Sub

Open in new window


From the Variance worksheet I want to only compare and copy over the rows where Column B text = Local Market.  As it is written I am returning all values in Column B.
0
Comment
Question by:jmac001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 27

Expert Comment

by:MacroShadow
ID: 40030756
Try this:
Sub aaa()
    Dim ChkSH As Worksheet
    Dim r As Row
    Dim ce As String

    Set ChkSH = Sheets("LM")
    ce = "Local Market"

    Sheets("Variance").Activate
    For Each r In Sheets("Variance").Range("a4:a" & Cells(Rows.Count, 1).End(xlUp).Row)
        Set findit = ChkSH.Range("a4:a3000").Find(what:=ce, LookIn:=xlValues, _
                                                  LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                                                  MatchCase:=False, SearchFormat:=False)

        If findit Is Nothing Then Range("A" & ce.Row).Copy _
           ChkSH.Range("a65000").End(xlUp).Offset(1, 0)

    Next
End Sub

Open in new window

0
 

Author Comment

by:jmac001
ID: 40032052
Hi,

Receiving User-defined type not defined compile error (Dim r As Row).  Attaching a sample of the workbook vba in Module 4.

Thanks
EE-Timeline-Data-2014.04.29.xlsm
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 40032473
Sorry my bad.

Sub aaa()
    Dim ChkSH As Worksheet
    Dim r As Range
    Dim ce As String

    Set ChkSH = Sheets("LM")
    ce = "Local Market"

    Sheets("Variance").Activate
    For Each r In Sheets("Variance").Range("a4:a" & Cells(Rows.Count, 1).End(xlUp).Row).Rows
        Set findit = ChkSH.Range("a4:a3000").Find(what:=ce, LookIn:=xlValues, _
                                                  LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                                                  MatchCase:=False, SearchFormat:=False)

        If findit Is Nothing Then Range("A" & r.Row).Copy _
           ChkSH.Range("a65000").End(xlUp).Offset(1, 0)

    Next
End Sub

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jmac001
ID: 40032511
Still have a problem all of the records are still being copied over
0
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 40032762
This is the quickest most efficient way to do what you want, it uses autofilter.

Sub aaa()
    Sheets("Variance").Range("A4:AC" & Cells(Rows.Count, 1).End(xlUp).Row).AutoFilter 2, "Local Market"
    Sheets("Variance").Range("A4:AC" & Cells(Rows.Count, 1).End(xlUp).Row).Copy Sheets("LM").Range("A65000").End(xlUp).Offset(1, 0)
    Sheets("Variance").ListObjects("Var").Range.AutoFilter Field:=2
End Sub

Open in new window

0
 

Author Comment

by:jmac001
ID: 40033093
This does workk.  In your opinion, I have to consistanly update the report, it better to copy and repaste the values or do a comparison and add only the new values?
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 40033113
It will be much more efficient and a whole lot quicker to copy and paste all the the records.
0
 

Author Closing Comment

by:jmac001
ID: 40033119
Thanks for you help and the alternative solution
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
can excel files with data model work in excel 2010? 3 41
Paste Table from Excel VBA to the PowerPoint 2010 18 55
Excel graph in access report 1 33
Excel Date Question 8 46
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question