Solved

Copy Values VBA  between two sheets

Posted on 2013-06-28
2
178 Views
Last Modified: 2013-07-04
I am needing to copy data from Sheet1 to Sheet2 if Sheet1 column P is True.  The code below finds True but does not copy the values...  Can someone please take a look at the code.  I am also needing to paste the values on Sheet2 on the last empty row.
Thank you.  


Dim sh1 As Worksheet: Set sh1 = ThisWorkbook.Sheets("Master")
Dim sh2 As Worksheet: Set sh2 = ThisWorkbook.Sheets("Validation")
Dim RowSh1 As Long, RowSh2 As Long

RowSh1 = sh1.Range("A" & Rows.Count).End(xlUp).Row + 1
RowSh2 = sh2.Range("A" & Rows.Count).End(xlUp).Row

For x = 1 To RowSh1

    If Len(sh1.Cells(x, "P")) = True Then
       
        sh1.Cells(x, "A").Copy sh2.Cells(RowSh2, "B")
       
        sh1.Cells(x, "C").Copy sh2.Cells(RowSh2, "A")
       
     
   
        RowSh2 = RowSh2 + 1
       
    End If

Next x

End Sub
0
Comment
Question by:leezac
2 Comments
 
LVL 46

Expert Comment

by:Martin Liss
ID: 39286079
What actual value do you use in column P to show that it's True?
0
 
LVL 5

Accepted Solution

by:
DOSLover earned 500 total points
ID: 39286104
You are using Len function to check the value of P column, Instead I think the code should check the content of the cell. That is to say, your code copies data correctly from Master to Validation sheet, if you change the following line
          If Len(sh1.Cells(x, "P")) = True Then
To
          If  sh1.Cells(x, "P") = True Then
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

867 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now