我正在制作一个宏,它将搜索列表并在第一个具有“spectraseven”的列中找到所有条目。这会将这些记录复制到每个条目的工作表中。
当工作簿中只有一张工作表时,此宏有效,但当工作簿中有更多工作表时,它会object or variable with block not set
在末尾带有箭头的行给出错误。( If FoundCell.Address = FirstAddr Then
)
Function mySheetData(SheetName As String) As Boolean
'
'By Joe Was
'This adds a sheet and names it "Test."
'SheetName = Sheets(1).Range("a1")
Sheets.Add.Name = SheetName
'This selects your new sheet and moves it after sheet "Sheet3," which could be any sheet name.
Sheets(SheetName).Select
Sheets(SheetName).Move After:=Sheets(Worksheets.Count)
'this selects the sheet with the data and its range.
Sheets(1).Select
Range("A1:c20").Select
'This will copy and paste the data to your new sheet "Test."
Selection.Copy
Sheets(SheetName).Select
ActiveSheet.Paste
'At this point your data will be on the new sheet and selected for the next step.
End Function
'copy from template sheet
'add information from each summary sheet to the tech sheets
'Function MoveToTables(manName As String, startCell As Integer, cellRange As String) As Boolean
Sub testWild()
startCell = 1
Dim FoundCell As Range
Dim LastCell As Range
Dim FirstAddr As String
Dim technum As String
cellRange = "e1:e500"
topCount = startCell
With Range("e1:e500")
Set LastCell = .Cells(.Cells.Count)
End With
Dim findString As String
findString = "SPECTRASEVEN*"
Set FoundCell = Sheets(1).Range(cellRange).Find(what:=findString, After:=LastCell)
If Not FoundCell Is Nothing Then
FirstAddr = FoundCell.Address
End If
Do Until FoundCell Is Nothing
Debug.Print FoundCell.Address
Count = FoundCell.Row
technum = Right(FoundCell, 4)
Set FoundCell = Range(cellRange).FindNext(After:=FoundCell)
temp = mySheetData(technum)
' vv This is the line with the error vv
If FoundCell.Address = FirstAddr Then
Exit Do
End If
Loop
End Sub