Excel startRange.offset-对象不支持此属性或方法

Excel startRange.offset-对象不支持此属性或方法,excel,vba,range,runtime-error,offset,Excel,Vba,Range,Runtime Error,Offset,运行下面的代码时收到错误。这在上个月起作用了,自从我更新了October的数据后,它似乎停止了作用 脚本应该从Derek_Calc中获取数据,这是一个每天登录到服务器上应用程序的所有登录的列表。然后对这些数据进行压缩,以突出显示某一天每小时有多少人登录 以下行用于设置将数据添加到表中的日期信息以及在DEREK_Calcs中检查的日期: Set tempRange = target1.Range("B1706:B1736") Sub PopulateConcurrency() 'for re-

运行下面的代码时收到错误。这在上个月起作用了,自从我更新了October的数据后,它似乎停止了作用

脚本应该从Derek_Calc中获取数据,这是一个每天登录到服务器上应用程序的所有登录的列表。然后对这些数据进行压缩,以突出显示某一天每小时有多少人登录

以下行用于设置将数据添加到表中的日期信息以及在DEREK_Calcs中检查的日期:

Set tempRange = target1.Range("B1706:B1736")

Sub PopulateConcurrency()  'for re-populating specific dates for the 'DEREK_Concurrency_Logins' sheet
                                'UPDATE THE DATE RANGE below!

    Dim thisBook As Workbook
    Dim target1 As Worksheet
    Dim target2 As Worksheet
    Dim dbSheetNames(1 To 2) As String
    Dim cell As Variant
    Dim cell2 As Variant
    Dim searchDate As String
    Dim firstColDate As Boolean
    Dim userIdLoginCount As Long
    Dim startHour As String
    Dim endHour As String
    Dim startDateTime As Date
    Dim endDateTime As Date
    Dim startDateHour As Date
    Dim endDateHour As Date
    Dim hourCounter As Integer
    Dim startRange As Range
    Dim endRange As Range
    Dim tempString As String
    Dim counter As Long
    Dim userIds() As Long
    Dim uniqueIds As Collection, c
    Dim targCellRange As Range
    Dim tempRange As Range
    Dim tempRange2 As Range

        dbSheetNames(1) = "DEREK_Concurrency_Logins"
        dbSheetNames(2) = "DEREK_Calcs"

        Set thisBook = ThisWorkbook
        Set target1 = thisBook.Sheets(dbSheetNames(1))
        Set target2 = thisBook.Sheets(dbSheetNames(2))

        'prepare variables
        userIdLoginCount = 0
        hourCounter = 0

        'de-activate re-calculations for this sheet as these will be updated later
        target1.EnableCalculation = False
        target2.EnableCalculation = False

        'stop screen refreshing
        Application.ScreenUpdating = False

        Set tempRange = target1.Range("B1706:B1736") 'UPDATE THE DATE RANGE FROM COLUMN B Of THE 'DEREK_Concurrency_Logins' sheet
        For Each cell In tempRange   'loop through each date in the DEREK_Concurrency_User_Logins sheet

            searchDate = cell.Value
            searchDate = Format(searchDate, "dd/mm/yyyy")
            firstColDate = True
            hourCounter = 0

            For hourCounter = 0 To 16  'loop to next hour time range

                'get start hour and end hour
                startHour = target1.Cells(2, (3 + hourCounter))
                startHour = Format(startHour, "hh:mm")
                endHour = target1.Cells(2, (4 + hourCounter))
                endHour = Format(endHour, "hh:mm")

                'prepare variables
                Erase userIds
                Set uniqueIds = Nothing
                Set uniqueIds = New Collection
                userIdLoginCount = 0
                counter = 0

                With target2

                    Set tempRange2 = target2.Range("DEREK_LoginDaily")
                        For Each cell2 In tempRange2  'loop through each cell2 In DEREK_LoginDaily

                            If (StrComp(searchDate, cell2.Value) = 0) Then 'check for date match

                                If firstColDate = False Then

                                Set startRange = cell2
                                Set endRange = cell2

                                'get start and end hours for the hour period
                                startDateTime = startRange.Offset(0, 7).Value
                                endDateTime = endRange.Offset(0, 8).Value

                                'get the login start and finish times
                                tempString = Day(startDateTime) & "/" & Month(startDateTime) & "/" & Year(startDateTime) & " " & Format(startHour, "hh:mm")
                                startDateHour = CDate(tempString)

                                tempString = Day(endDateTime) & "/" & Month(endDateTime) & "/" & Year(endDateTime) & " " & Format(endHour, "hh:mm")
                                endDateHour = CDate(tempString)

                                    If startDateTime <= startDateHour And endDateTime >= endDateHour Then

                                        Sheets(dbSheetNames(2)).Select
                                        startRange.Offset(0, 10).Select
                                        startRange.Offset(0, 10).Activate
                                        ReDim Preserve userIds(counter)

                                        If (startRange.Offset(0, 10).Length > 0) Then
                                            If startRange.Offset(0, 6).Value = 1 Then
                                            userIds(counter) = startRange.Offset(0, 10).Value
                                            End If
                                        End If

                                        counter = counter + 1 'increment counter

                                    End If 'end hour concurency check

                                Else 'if firstColDate is True

                                    startHour = target1.Cells(2, 2) 'code for 7am - 8am, set startHour to 07:00
                                    endHour = target1.Cells(2, 4) 'set endHour to 08:00

                                    Set startRange = cell2
                                    Set endRange = cell2

                                    'get start and end hours for the hour period
                                    startDateTime = startRange.Offset(0, 7).Value
                                    endDateTime = endRange.Offset(0, 8).Value

                                    'get the login start and finish times
                                    tempString = Day(startDateTime) & "/" & Month(startDateTime) & "/" & Year(startDateTime) & " " & Format(startHour, "hh:mm")
                                    startDateHour = CDate(tempString)

                                    tempString = Day(endDateTime) & "/" & Month(endDateTime) & "/" & Year(endDateTime) & " " & Format(endHour, "hh:mm")
                                    endDateHour = CDate(tempString)

                                    If startDateTime <= startDateHour And endDateTime >= endDateHour Then

                                        Sheets(dbSheetNames(2)).Select
'THIS IS WHERE THE ERROR IS :-(
                                        startRange.Offset(0, 10).Select
                                        startRange.Offset(0, 10).Activate
                                        ReDim Preserve userIds(counter)

                                        If (startRange.Offset(0, 10).Length > 0) Then
                                            If startRange.Offset(0, 6).Value = 1 Then
                                                userIds(counter) = startRange.Offset(0, 10).Value
                                            End If
                                        End If

                                        counter = counter + 1 'increment counter

                                    End If 'end hour concurency check
                                End If 'end if firstColDate
                            End If 'end if a date match

                        Next cell2 'loop through each cell2 In DEREK_LoginDaily

                    End With

                    'get unique values by putting array into a collection
                    On Error Resume Next
                    For Each c In userIds
                        If Not IsEmpty(c) Then
                            uniqueIds.Add Item:=c, Key:=CStr(c)
                        End If
                    Next c

                    'populate target cell
                    Set targCellRange = cell
                    targCellRange.Offset(0, (2 + hourCounter)) = (uniqueIds.count)

                    firstColDate = False

                Next hourCounter 'loop to next hour time range

                firstColDate = True

            Next cell 'loop through each date in the DEREK_Concurrency_User_Logins sheet

            MsgBox "Complete"

End Sub
Set tempRange=target1.Range(“B1706:B1736”)
Sub PopulateConcurrency(),用于重新填充“DEREK_Concurrency_Logins”工作表的特定日期
'更新下面的日期范围!
把这本书当作工作簿
将target1变暗为工作表
Dim target2 As工作表
尺寸dbSheetNames(1到2)作为字符串
变暗细胞
Dim cell2作为变体
将搜索日期设置为字符串
Dim firstColDate作为布尔值
Dim userIdLoginCount尽可能长
朦胧的星空如弦
朦胧的尾声
Dim startDateTime作为日期
Dim endDateTime作为日期
暗淡的startDateHour作为日期
Dim endDateHour作为日期
Dim hourCounter为整数
暗星际范围
Dim endRange作为范围
将字符串设置为字符串
昏暗的柜台一样长
Dim userIds()的长度为
作为集合的暗淡唯一标识,c
Dim targCellRange As Range
暗温度范围作为范围
变暗tempRange2作为范围
dbSheetNames(1)=“DEREK\u并发\u登录”
dbSheetNames(2)=“DEREK_Calcs”
设置thisBook=ThisWorkbook
Set target1=thisBook.Sheets(dbSheetNames(1))
Set target2=thisBook.Sheets(dbSheetNames(2))
'准备变量
userIdLoginCount=0
小时计数=0
'取消激活此工作表的重新计算,因为这些计算将在以后更新
target1.EnableCalculation=False
target2.EnableCalculation=错误
'停止屏幕刷新
Application.ScreenUpdating=False
Set tempRange=target1.Range(“B1706:B1736”)'从“DEREK_并发登录”表的B列更新日期范围
对于tempRange中的每个单元格,通过DEREK_并发用户登录表中的每个日期循环
searchDate=cell.Value
searchDate=格式(searchDate,“dd/mm/yyyy”)
firstColDate=True
小时计数=0
对于hourCounter=0到16'循环到下一个小时的时间范围
'获取开始时间和结束时间
startHour=target1.单元格(2,(3+小时计数器))
startHour=格式(startHour,“hh:mm”)
endHour=target1.单元格(2,(4+小时计数器))
endHour=格式(endHour,“hh:mm”)
'准备变量
删除用户标识
设置uniqueid=Nothing
Set uniqueid=新集合
userIdLoginCount=0
计数器=0
与target2
设置tempRange2=target2.Range(“DEREK_logindaly”)
对于tempRange2'中的每个cell2,通过DEREK_Loginday中的每个cell2循环
如果(StrComp(searchDate,cell2.Value)=0),则“检查日期匹配”
如果firstColDate=False,则
设置startRange=cell2
设置endRange=cell2
'获取小时周期的开始和结束时间
startDateTime=startRange.Offset(0,7).Value
endDateTime=endRange.Offset(0,8).Value
'获取登录开始和完成时间
tempString=Day(startDateTime)&“/”和Month(startDateTime)&“/”和Year(startDateTime)&“&格式(startHour,“hh:mm”)
startDateHour=CDate(tempString)
tempString=Day(endDateTime)&“/”和Month(endDateTime)&“/”和Year(endDateTime)&“&格式(endHour,“hh:mm”)
endDateHour=CDate(tempString)
如果startDateTime=endDateHour,则
图纸(dbSheetNames(2))。选择
起始偏移量(0,10)。选择
起始偏移量(0,10)。激活
重拨保留用户标识(计数器)
如果(起始偏移量(0,10).Length>0),则
如果startRange.Offset(0,6).Value=1,则
userid(计数器)=startRange.Offset(0,10).Value
如果结束
如果结束
计数器=计数器+1'增量计数器
如果结束,则结束小时一致性检查
如果firstColDate为True,则为Else
startHour=target1。单元格(2,2)“代码用于上午7点至上午8点,将startHour设置为07:00
endHour=target1。单元格(2,4)“将endHour设置为08:00
设置startRange=cell2
设置endRange=cell2
'获取小时周期的开始和结束时间
startDateTime=startRange.Offset(0,7).Value
endDateTime=endRange.Offset(0,8).Value
'获取登录开始和完成时间
tempString=Day(startDateTime)&“/”和Month(startDateTime)&“/”和Year(startDateTime)&“&格式(startHour,“hh:mm”)