MD, et al,
The short answer to my question is that I forgot to 'set' my wb and ws assignments. New code replaces what I first posted.
Here's where my original query began:
The next project that I have is to write code to move selected data from my Grade & "_INFO.xls" file to another named Grade & "_Diagnostic Assessment.xls". Here is what I have so far. I copied the wb1/wb2 (here, called wbInfo, wbDiag) from the code MD gave me for the last project. As the comment says, I'm getting an error that I don't follow. The files are open on my desktop and yet the code, here, is not recognizing the first one.
My goal at the moment is to have autofilter find me only those lines in INFO that have a particular Standard code associated with them. Once I have that I'll add in using "activecell" to identify which row of those filtered I want to use, and then use offset to get the various pieces of data to move to the Diagnostic Assessment worksheet/workbook.
[vba]Option Explicit
Sub Move_Data()
Dim wbInfo As Workbook, wsInfo As Worksheet, FilenameInfo As String, LastInfoRow As Long
Dim wbDiag As Workbook, wsDiag As Worksheet, FilenameDiag As String, LastDiagRow As Long
Dim Grade As String, std As String, LastInfoCol As Long, LastDiagCol As Long
Dim rngInfo As Range, rngDiag As Range, InfoCol As Long, DiagCol As Long
Dim wb1 As Workbook
' InfoFile = OpenFile("Info")
' DiagFile = OpenFile("Diag")
Grade = "G4"
Set wbInfo = Workbooks(Grade & "_INFO.xls") ' <<< Err 91:Object Var or With Block Var not set ??
Set wbInfo = Workbooks("G4_INFO.xls")
' Set wsInfo = wbInfo.Worksheet("INFO")
With wsInfo
Grade = Left(.Cells(2, 2).Value, 2)
LastInfoRow = .UsedRange.Rows
LastInfoCol = .UsedRange.Columns
InfoCol = .Range("F1").Column
Set rngInfo = .Range(Cells(2, 1)).Resize(LastInfoRow, LastInfoCol) 'Column T
std = .Range("F2").Text
End With
wbDiag = Workbooks(Grade & " - Diagnostic Assessment.xls")
wsDiag = wbDiag.Worksheets("DA NL " & Grade)
With wsDiag
LastDiagRow = .UsedRange.Rows
LastDiagCol = .UsedRange.Columns
DiagCol = .Range("T1").Column
Set rngDiag = .Range(Cells(2, 1)).Resize(LastDiagRow, LastDiagCol) 'Column F
' std = ActiveCell.Text
With rngInfo
.AutoFilter
.AutoFilter Field:=InfoCol, Criteria1:=std
If Not rngInfo Is Nothing Then
.SpecialCells (xlCellTypeVisible)
If Not rngInfo Is Nothing Then MsgBox "Nothing Selected. Try next Std.", vbOKOnly, "Filter INFO File"
End If
End With
End Sub
[/vba]
Advice and counsel is cheerfully sought. And, don't worry, I'll carve code out and place it in Subs and Functions as may be appropriate. Right now, a single file is adequate for testing.
Thanks,