I'm new to this so here goes
I have a macro that finds text in a Workbook (named Tester) with a Worksheet (named Estimate1) and copies to another worksheet (named Works) which I would rather save to another workbook (Cost Schedule.xlsm) but can only get it to send to a worksheet as when I try to open Cost Schedule it has an error 1004 cannot open file extension.
I then need it to copy
I have a macro that finds text in a Workbook (named Tester) with a Worksheet (named Estimate1) and copies to another worksheet (named Works) which I would rather save to another workbook (Cost Schedule.xlsm) but can only get it to send to a worksheet as when I try to open Cost Schedule it has an error 1004 cannot open file extension.
I then need it to copy
Code:
Sub EstimatetoWorkSchedule()
Dim SheetName As String
SheetName = "Estimate1"
SheetName = InputBox("enter the name of a sheet to use", "sheet name", SheetName)
Dim i As Long
Dim MyCol As Integer
Dim MyRow As Integer
Range("B4:M656").Select
Selection.ClearContents
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 2
MyRow = 4
For i = 1 To 1
If Sheets(SheetName).Range("B" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("B" & i).Value
MyCol = 2
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 2
MyRow = 12
For i = 12 To 12
If Sheets(SheetName).Range("A" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("A" & i).Value
MyCol = 2
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 2
MyRow = 14
For i = 14 To 14
If Sheets(SheetName).Range("A" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("A" & i).Value
MyCol = 2
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 2
MyRow = 20
For i = 20 To 20
If Sheets(SheetName).Range("A" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("A" & i).Value
MyCol = 2
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 2
MyRow = 27
For i = 27 To 30
If Sheets(SheetName).Range("A" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("A" & i).Value
MyCol = 2
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 2
MyRow = 32
For i = 32 To 32
If Sheets(SheetName).Range("A" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("A" & i).Value
MyCol = 2
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 2
MyRow = 36
For i = 36 To 37
If Sheets(SheetName).Range("A" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("A" & i).Value
MyCol = 2
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 2
MyRow = 43
For i = 43 To 44
If Sheets(SheetName).Range("A" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("A" & i).Value
MyCol = 2
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 3
MyRow = 43
For i = 43 To 44
If Sheets(SheetName).Range("A" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("C" & i).Value
MyCol = 3
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 2
MyRow = 46
For i = 46 To 46
If Sheets(SheetName).Range("A" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("A" & i).Value
MyCol = 2
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 3
MyRow = 46
For i = 46 To 46
If Sheets(SheetName).Range("A" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("C" & i).Value
MyCol = 3
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 2
MyRow = 48
For i = 48 To 48
If Sheets(SheetName).Range("A" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("A" & i).Value
MyCol = 2
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 3
MyRow = 48
For i = 48 To 48
If Sheets(SheetName).Range("A" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("C" & i).Value
MyCol = 3
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 2
MyRow = 57
For i = 57 To 57
If Sheets(SheetName).Range("A" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("A" & i).Value
MyCol = 2
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 2
MyRow = 59
For i = 59 To 61
If Sheets(SheetName).Range("A" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("A" & i).Value
MyCol = 2
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 3
MyRow = 59
For i = 59 To 61
If Sheets(SheetName).Range("A" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("C" & i).Value
MyCol = 3
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 2
MyRow = 68
For i = 68 To 71
If Sheets(SheetName).Range("A" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("A" & i).Value
MyCol = 2
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 3
MyRow = 68
For i = 68 To 71
If Sheets(SheetName).Range("A" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("C" & i).Value
MyCol = 3
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 2
MyRow = 79
For i = 79 To 82
If Sheets(SheetName).Range("A" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("A" & i).Value
MyCol = 2
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 2
MyRow = 87
For i = 87 To 87
If Sheets(SheetName).Range("A" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("A" & i).Value
MyCol = 2
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 2
MyRow = 91
For i = 91 To 91
If Sheets(SheetName).Range("A" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("A" & i).Value
MyCol = 2
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 2
MyRow = 103
For i = 103 To 105
If Sheets(SheetName).Range("A" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("A" & i).Value
MyCol = 2
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 2
MyRow = 109
For i = 109 To 172
If Sheets(SheetName).Range("A" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("A" & i).Value
MyCol = 2
MyRow = MyRow + 1
End If
Next i
LR = Sheets(SheetName).Range("A" & Rows.Count).End(xlUp).Row
MyCol = 2
MyRow = 765
For i = 765 To 765
If Sheets(SheetName).Range("l" & i).Value <> "" Then
Sheets("Work Schedule").Cells(MyRow, MyCol).Value = Sheets(SheetName).Range("m" & i).Text
MyCol = 2
MyRow = MyRow + 1
End If
Next i
'
Range("B4:C657").Select
Selection.AutoFilter
ActiveSheet.Range("$B$3:$C$657").AutoFilter Field:=1, Criteria1:="<>"
Columns("H:I").Select
Selection.EntireColumn.Hidden = True
End Sub