Solved

Copy Values VBA  between two sheets

Posted on 2013-06-28
2
181 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
[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
2 Comments
 
LVL 47

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

Industry Leaders: 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!

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

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