Solved

Copy data from one sheet to another

Posted on 2013-06-03
2
304 Views
Last Modified: 2013-06-03
I need VBA help to do the following.    


If column AP sheet 4 is null then
copy ColumnC of sheet 4 to column A sheet 3
then copy column L  of sheet 4 to column B sheet3
then copy column F of sheet 4 to column C Sheet 3

for each row until there are no other blank cells in AP or first blank row for column A Sheet4.

Thanks in advance
0
Comment
Question by:leezac
2 Comments
 
LVL 24

Accepted Solution

by:
Steve earned 500 total points
ID: 39217431
The attached should do it...

Sub CopyData()

Dim sh3 As Worksheet: Set sh3 = ThisWorkbook.Sheets("Sheet3")
Dim sh4 As Worksheet: Set sh4 = ThisWorkbook.Sheets("Sheet4")
Dim RowSh3 As Long, RowSh4 As Long

RowSh3 = sh3.Range("A" & Rows.Count).End(xlUp).Row + 1
RowSh4 = sh4.Range("A" & Rows.Count).End(xlUp).Row

For x = 1 To RowSh4

    If Len(sh4.Cells(x, "AP")) = 0 Then
        
        sh4.Cells(x, "C").Copy sh3.Cells(RowSh3, "A")
        
        sh4.Cells(x, "L").Copy sh3.Cells(RowSh3, "B")
        
        sh4.Cells(x, "F").Copy sh3.Cells(RowSh3, "C")
    
        RowSh3 = RowSh3 + 1
        
    End If

Next x

End Sub

Open in new window


**note** Example workbook uses P rather than AP, but code above uses AP
If you require the code to be commented, feel free to ask.
Example-Copy.xlsm
0
 

Author Closing Comment

by:leezac
ID: 39217518
Thanks - that was perfect and easy to understand. Thank you!!!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
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 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.

760 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

19 Experts available now in Live!

Get 1:1 Help Now