I have a worksheet that I have to export daily that consists of work schedules. What I am trying to do is manipulate the data in the .csv file before copying it over to my workbook. For any given day the tech could have up to 4 schedules for 1 day. I am trying to find the column that the Regular shift is in and move it to column E.
| Supervisor | Technician | On Duty? | Earliest Route Time | Shift 1 Type | Shift 1 Start | Shift 1 End | Shift 2 Type | Shift 2 Start | Shift 2 End |
|------------|------------|----------|---------------------|--------------|---------------|-------------|--------------|---------------|-------------|
| Harold | Doug | No | | Meetings | 8:00 AM | 9:30 AM | Regular | 9:30 AM | 4:30 PM |
| Harold | Greg | No | | Meetings | 8:00 AM | 9:30 AM | Regular | 9:00 AM | 4:30 PM |
| | | | | | | | | | |
I have tried to implement the solution from (Why does Range work, but not Cells?) there was another one but I seem to have lost it.
Sub test_cell()
Dim sh1 As Worksheet
Dim x as Integer
Dim col as Integer
For Each w In Workbooks 'loop through open workbooks
If w.Name = "tech_shifts_now.csv" Then
w.Activate
Sheets("tech_shifts_now").Select
Set sh1 = ActiveWorkbook.Sheets("tech_shifts_now")
x = 3
If Cells(x, 5) <> "Regular" Then
With sh1
.Range(.Cells(x, 5), .Cells(x, 7)).Copy Destination:=.Range(.Cells(x, 17)) 'Move current data to Q
End With
'Range("E" & x & ":G" & x).Copy Range("Q" & x)
'Find the column that regular shift is in
Rows(x).Find(What:="Regular", LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
'get the columns number
col = ActiveCell.Column
'copy the data for regular to Column E
Range(Cells(x, col), Cells(x, col + 2)).Copy Destination:=Range(Cells(x, 5))
'Copy for Column Q to where we just removed the Regular data from
Range("Q" & x & ":S" & x).Copy Range(Cells(x, col))
End If
End If
Next w
End Sub
I am receiving error 1004 Method Range of Object _worksheet failed
when it gets to .Range(.Cells(x, 5), .Cells(x, 7)).Copy Destination:=.Range(.Cells(x, 17))