|
本帖最后由 cmo9020 于 2023-6-10 16:47 编辑
各位导师周末愉快...
遇到一个难题,请教各位导师一下
现在需要2段代码
第一段是
1.在sheet1输入时间它会自动导入到"范本"工作表
如果是早上08:00~12:00 会输入到"范本"工作表G2单元格
如果是下午12:00~00:00 会输入到"范本"工作表I2单元格
另一格就是自动显示NA
Sub Search()
Dim searchString As String
Dim templateSheets As Variant
Dim dataSheet As Worksheet
Dim i As Long
Dim mergeRange As Range
Dim fillRange As Range
Dim quantity1 As Variant
Dim quantity2 As Variant
Dim quantity3 As Variant
searchString = Sheets("Sheet1").Range("A9").Value
templateSheets = Array(Sheets("范本"))
Set dataSheet = Sheets("Sheet1")
quantity1 = dataSheet.Range("B9").Value
quantity2 = dataSheet.Range("C9").Value
quantity3 = dataSheet.Range("D9").Value
For Each templateSheet In templateSheets
For i = 1 To templateSheet.Cells(templateSheet.Rows.Count, "A").End(xlUp).Row
If templateSheet.Cells(i, "A").MergeArea.Cells(1, 1).Value = searchString Then
Set mergeRange = templateSheet.Cells(i, "A").MergeArea
Exit For
End If
Next i
If Not mergeRange Is Nothing Then
If mergeRange.Cells.Count > 1 Then
Set fillRange = mergeRange.Offset(0, 5).Resize(mergeRange.Rows.Count, 2)
Else
Set fillRange = mergeRange.Offset(0, 5).Resize(, 2)
End If
Select Case templateSheet.Name
Case "范本"
fillRange.Value = Array(quantity1, "")
End Select
End If
Next templateSheet
End Sub
|
|