Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Copy Values VBA  between two sheets

Posted on 2013-06-28
2
Medium Priority
?
190 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 49

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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
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 demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

704 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