Portucale
Member
Hi,
I currently use the code below to extract just the columns required from a workbook source, but I am encountering a small issue, as in the source we have a column name as "ADV_OffphoneHrs" and another column named as "ADV_Offphone", when the procedure run it picks up the data from the first column "ADV_OffphoneHrs" when in fact I need the data from the "ADV_Offphone". OK I know that a change in the headers would be a solution but as we have other reports and Databases running of the source I come this way to ask if there is any other solution.
Many thanks for the help,
I currently use the code below to extract just the columns required from a workbook source, but I am encountering a small issue, as in the source we have a column name as "ADV_OffphoneHrs" and another column named as "ADV_Offphone", when the procedure run it picks up the data from the first column "ADV_OffphoneHrs" when in fact I need the data from the "ADV_Offphone". OK I know that a change in the headers would be a solution but as we have other reports and Databases running of the source I come this way to ask if there is any other solution.
Code:
Private Sub ADV_Hist()
Dim wsO As Worksheet
Dim wsF As Worksheet
Dim i As Integer
Application.ScreenUpdating = False
Worksheets.Add(after:=Worksheets("CEM")).Name = "ADV_Hist"
Set wsO = Worksheets("Advisor")
Set wsF = Worksheets("ADV_Hist")
myColumns = Array("ADV_Month ", "ADV_Payroll", "ADV_AgentID", "ADV_Name", _
"ADV_ComRate", "ADV_HCGroup", "ADV_NetRevenue", "ADV_HCScore", "ADV_AbsHours", _
"ADV_AbsencePerc", "ADV_HolidayDays", _
"ADV_HappyCustomer", "ADV_Value", "ADV_Holiday", "ADV_OffPhone", "ADV_Combined")
With wsO.Range("A1:AW1")
For i = 0 To UBound(myColumns)
On Error Resume Next
.Find(myColumns(i)).EntireColumn.Copy Destination:=wsF.Cells(1, i + 1)
Err.Clear
Next i
End With
Set wsO = Nothing
Set wsF = Nothing
Sheets("ADV_Hist").Select
With ActiveWorkbook.Sheets("ADV_Hist").Tab
.Color = 255
.TintAndShade = 0
End With
Range("A1").Select
Application.ScreenUpdating = True
End Sub
Many thanks for the help,