Hello Forumers!
I would like to ask your help as I am struggling with this case for days and I cannot figure out what can cause this "runtime error 9 subscript out of range error". I would give some detail before the code.
There are two files "A.xlsm" and "B.xls". File "A" is open (this is where I would like to run my macro from on file "B") and "B" should be opened and a specific worksheet called "data" should be activated and copied every data from that sheet row by row to file "A" if a colum value is a special word. In file "A" at the start I create a sheet with the current date which is important for me to stay this way. This sheet is totally empty.
The code:
Sub copy_between_files()
Dim curr_date As String
Dim intRow
Dim intLastRow
curr_date = Format(Now(), "mm-dd-yy")
Sheets.Add After:=Sheets(Sheets.Count) 'inserts the current date labeled worksheet into file A
Worksheets(Worksheets.Count).Activate
ActiveSheet.Name = curr_date
Workbooks.Open Filename:="C:\Macros\B.xls" 'opens the datasource file
Windows("B.xls").Activate
Sheets("Data").Select 'selecting the special sheet in file B
intLastRow = ActiveSheet.UsedRange.Rows.Count
Range("A1").Select
For intRow = 1 To intLastRow Step 1
Rows(intRow).Select
If Cells(intRow, 5).Value = "specialword" Then
Cells(intRow, 1).Select
Selection.EntireRow.Copy
Windows("A.xlsm").Activate
Sheets(curr_date).Select
Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Select
ActiveSheet.Paste
End If
Windows("B.xls").Activate
Sheets("Data").Select
Next intRow
Windows("A.xlsm").Activate
End Sub
If there would be any guesses , hints or advice I would really appreciate it! I hope my description can be used to guide you to my problem.
Bookmarks