リストを検索して、最初に「spectraseven」が含まれる列のすべてのエントリを見つけるマクロを作成しています。これは、これらのレコードを各エントリのシートにコピーするためのものです。
このマクロは、ブックにシートが1つしかない場合に機能しますが、それ以上ある場合は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