Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why my VBA not copy from column A instead of column F?

I’m a beginner for using VBA code to improved my working efficiency, I wrote a code to copy and paste columns from Sheet W2W to Sheet OTD Analysis when column F value doesn’t exist in OTD Analysis. But this code only copied column F:AU instead of A:AU, I wonder what’s wrong in the code and how I can resolve it. Please kindly help!

Sub Transfer()

    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Sheets("W2W").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim rng As Range
    Dim foundVal As Range
    For Each rng In Sheets("W2W").Range("F2:F" & LastRow)
        Set foundVal = Sheets("OTD Analysis").Range("F:F").Find(rng, LookIn:=xlValues, lookat:=xlWhole)
        If foundVal Is Nothing Then
            rng.Columns("A:AU").Copy
            Sheets("OTD Analysis").Activate
            b = Sheets("OTD Analysis").Cells(Rows.Count,1).End(xlUp).Row
            Sheets("OTD Analysis").Cells(b + 1, 1).Select
            ActiveSheet.Paste
        End If
    Next rng
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    
End Sub

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You want Columns("A:AU") in reference to the entire row.

rng.EntireRow.Columns("A:AU").Copy
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading