Hello Experts,
Can someone please help me with a Excel VBA code to extract the values in columns A & B in the Data tab to the Data1 tab and place the data in Columns A & B starting in A3 with the header in A2.
I want the data extracted if the values in Column H of the Data Tab are Account OR C.O.D.
Sub TransferData()
Dim lngLastRow As Long
Dim lngRow As Long
Dim wsData As Worksheet
Dim wsDest As Worksheet
Const DATE_COL = "C"
Set wsData = ThisWorkbook.Worksheets("Data")
Set wsDest = ThisWorkbook.Worksheets("Data2")
With Application
.EnableEvents = False
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
wsDest.UsedRange.Cells.Offset(1, 0).ClearContents
With wsData
lngLastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For lngRow = 2 To lngLastRow
.Range("A" & lngRow & ":B" & lngRow).Copy wsDest.Range("A" & lngRow + 1)
Select Case .Range("H" & lngRow)
Case "Account", "C.O.D."
.Range("H" & lngRow).Copy wsDest.Range(DATE_COL & lngRow + 1)
End Select
Next
End With
wsDest.Activate
With Application
.Calculation = xlCalculationAutomatic
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
Select Case .Range("H" & lngRow)
Case "Account", "C.O.D."
.Range("H" & lngRow).Copy wsDest.Range(DATE_COL & lngRow + 1)
End Select