Copy excel data from one sheet to another

829 Views Asked by At

I have an excel sheet named as "Task" which contains two tabs "Data" and "DB-Task". I want to copy data from sheet "Data" to "DB-Task". Sheet "Data" has five columns (e.g. A,B,C,D,E,F). I want that if some one enter data in first row it should be transferred to another tab. If any of the columns is not filled it should give a popup to enter values before transferring data to another sheet . And In case the second row has all data it should get transferred to another sheet and only give error for first row .

I am using below code for copying data and it is successfully copying data from one sheet to another . Now I am not sure how should I use if condition effectively so that I can achieve what I want

Dim sheet1 As Worksheet
Dim sheet2 As Worksheet
Dim endrow As Long

Set sheet1 = ActiveWorkbook.Sheets("Data")
Set sheet2 = ActiveWorkbook.Sheets("Delivery Task")

Application.ScreenUpdating = False

         endrow = sheet2.Range("A" & sheet2.Rows.Count).End(xlUp).Row
         sheet1.Range("A2:E10").Copy
         sheet2.Activate
         sheet2.Range("A" & endrow + 1).PasteSpecial Paste:=xlPasteValues
         Application.CutCopyMode = False
         sheet1.Activate
         Range("A2:E10").ClearContents

End Sub
1

There are 1 best solutions below

2
On

Eventhough I am new to VBA Let me help.You can use this sub to check if all the columns are filled for a particular row and based on the value of column 8 you can copy and transfer file

FindEmptyCells()
     Dim colnum As Long
     Dim rownum As Long
     Dim lastrow As Long
     lastrow = Sheets("Data").Range("A" & Rows.count).End(xlUp).Row
     For rownum = 1 To lastrow
     For colnum = 1 To 5
      If IsEmpty(Cells(rownum, colnum)) Then   '<== To Check for Empty Cells
     Cells(rownum, 8) = "Data Incomplete"      '<== To Enter value if empty cell found
     Else
     Cells(rownum, 8) = "OK"
     End If
     Next colnum
     Next rownum
End Sub