Shanaka Fernando
New Member
- Joined
- Sep 30, 2021
- Messages
- 12
- Office Version
- 2010
- Platform
- Windows
how to copy row value until blank row to my VBA Code.( only highlighted area)
Sub MoveToDestination()
Dim destinationSheet As Worksheet, destRow As Long, destCol As Variant
Dim ws As Worksheet, wsRow As Long, wsCol As Variant
Dim columnHeader As Variant
Set destinationSheet = ThisWorkbook.Worksheets("data")
For Each ws In ThisWorkbook.Worksheets
If Not ws Is destinationSheet Then
For Each columnHeader In Array("ITEM#", "Item description")
With ws
wsCol = Application.Match(columnHeader, .Rows(17), 0)
If Not IsError(wsCol) Then
wsRow = .Cells(.Rows.Count, wsCol).End(xlUp).Row
destCol = Application.Match(columnHeader, destinationSheet.Rows(1), 0)
destRow = destinationSheet.Cells(destinationSheet.Rows.Count, destCol).End(xlUp).Row + 1
.Range(.Cells(18, wsCol), .Cells(wsRow, wsCol)).Copy destinationSheet.Cells(destRow, destCol)
Else
MsgBox "Column heading " & columnHeader & " not found in row 1 of " & .Name
End If
End With
Next
End If
Next
End Sub
Sub MoveToDestination()
Dim destinationSheet As Worksheet, destRow As Long, destCol As Variant
Dim ws As Worksheet, wsRow As Long, wsCol As Variant
Dim columnHeader As Variant
Set destinationSheet = ThisWorkbook.Worksheets("data")
For Each ws In ThisWorkbook.Worksheets
If Not ws Is destinationSheet Then
For Each columnHeader In Array("ITEM#", "Item description")
With ws
wsCol = Application.Match(columnHeader, .Rows(17), 0)
If Not IsError(wsCol) Then
wsRow = .Cells(.Rows.Count, wsCol).End(xlUp).Row
destCol = Application.Match(columnHeader, destinationSheet.Rows(1), 0)
destRow = destinationSheet.Cells(destinationSheet.Rows.Count, destCol).End(xlUp).Row + 1
.Range(.Cells(18, wsCol), .Cells(wsRow, wsCol)).Copy destinationSheet.Cells(destRow, destCol)
Else
MsgBox "Column heading " & columnHeader & " not found in row 1 of " & .Name
End If
End With
Next
End If
Next
End Sub