Solved

Copy Values VBA  between two sheets

Posted on 2013-06-28
2
176 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 45

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

708 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

15 Experts available now in Live!

Get 1:1 Help Now