无效或不合格的参考:lastRA = .Range(" A2"& .Rows.Count).End(xlUp).Row

时间:2017-05-22 10:04:28

标签: excel vba excel-vba

为什么会收到以下错误

  

无效或不合格的参考"

此行: <div class="form-group"> <label for="event-c" id="event-c" class="col-sm-4 control-label"><button type="button" class="btn btn-info" data-toggle="collapse" data-target="#demo">button</button></label> <div class="col-sm-7"> <div id="demo" class="collapse"> <form> <c:forEach items="${getNamesForLegend}" var="members"> <div class="radio"> <div class="panel-body" id="radio-c"><label><input type="radio" name="optradio" value=""><c:out value="${members.name}"/> <c:out value="${members.lastname}"/> <input type="hidden" name="a"<c:out value="${members.mySubordinate}"/>></div></label> </div> </c:forEach> </form> </div> </div> </div> 突出显示lastRA = .Range("A2" & .Rows.Count).End(xlUp).Row

.Rows

2 个答案:

答案 0 :(得分:1)

lastRA = .Range("A2" & .Rows.Count).End(xlUp).Row更改为

lastRA = ws.Range("A" & ws.Rows.Count).End(xlUp).Row

或者在With ws周围放置一个End With ... With ws lastRA = .Range("A" & .Rows.Count).End(xlUp).Row End With

Cells(linecount, "N")

您应该始终完全符合您的细胞/范围:
您的代码中的其他代码(例如ws.Cells(linecount, "N"))也应该符合工作表的要求,例如class ExampleMobilePhoneSpider(Spider): name = "example" allowed_domains = ["www.example.com", "example.com"] start_urls = ( 'https://search.example.com/api/search/?category=c11&pageno=0', ) custom_settings = { "ITEM_PIPELINES": { 'crawler_bot.pipelines.ExampleElectronicDevicePipeline': 100, } } def parse_item(self, response): js = json.loads(response.body.decode('utf-8')) hits = js['hits']['hits'] for counter, hit in enumerate(hits): l = ItemLoader(item=ProductDetail(), response=response) m = hits[counter]['_source'] # print(json.dumps(m, indent=4, sort_keys=True)) l.add_value('enTitle', m['EnTitle']) l.add_value('faTitle', m['FaTitle']) l.add_value('minPrice', {"value": m['MinPrice'], "updateDate": datetime.datetime.now()}) l.add_value('price', {"value": m['MinPriceList'], "updateDate": datetime.datetime.now()}) l.add_value('maxPrice', {"value": m['MaxPrice'], "updateDate": datetime.datetime.now()}) l.add_value('isActive', m['IsActive']) l.add_value('isEspecialOffer', m['IsSpecialOffer']) l.add_value('productCategories', m['ProductCategories'].split()) l.add_value('imagePath', m['ImagePath']) l.add_value('hasVideo', m['HasVideo']) l.add_value('productColorList', m['ProductColorList']) l.add_value('localID', m['Id']) l.add_value('url', response.url) l.add_value('project', "example") l.add_value('subject', ["electronic_device", "mobile_phone", "mobile"]) l.add_value('spider', self.name) l.add_value('server', socket.gethostname()) l.add_value('date', datetime.datetime.now()) l.add_value('collection', "electronic_device") file_path = "https://file.example.com/example/" l.add_value('images', image2base64.get_as_base64(file_path + m['ImagePath'])) yield l.load_item() def parse(self, response): base_url_mobile = 'https://search.example.com/api/search/?category=c11&pageno=' urls = [base_url_mobile + str(n) for n in range(2)] for url in urls: yield Request(urljoin(response.url, url), callback=self.parse_item)

答案 1 :(得分:1)

尝试以下方法之一...

Sub HighlightUpgrds()
    Dim lastRA As Long
    Dim ws As Worksheet
    Dim linecount As Long
    Dim rng1 As Range
    Dim rng2 As Range

    linecount = 2
    Set ws = Worksheets("Walk Ups")
    Set rng1 = ws.Cells(linecount, "N")
    Set rng2 = ws.Cells(linecount, "O")
    lastRA = ws.Range("A" & Rows.Count).End(xlUp).Row

    For i = 1 To lastRA
        If ws.Cells(linecount, "N") <> ws.Cells(linecount, "O") Then
            ws.Cells(linecount, "N").Interior.Color = RGB(255, 255, 64)
            ws.Cells(linecount, "O").Interior.Color = RGB(255, 255, 64)
        Else
        End If
        linecount = linecount + 1
    Next i
End Sub

Sub HighlightUpgrds()
    Dim lastRA As Long
    Dim ws As Worksheet
    Dim linecount As Long
    Dim rng1 As Range
    Dim rng2 As Range

    linecount = 2
    Set ws = Worksheets("Walk Ups")
    With ws
        Set rng1 = .Cells(linecount, "N")
        Set rng2 = .Cells(linecount, "O")
        lastRA = .Range("A" & .Rows.Count).End(xlUp).Row

        For i = 1 To lastRA
            If .Cells(linecount, "N") <> .Cells(linecount, "O") Then
               .Cells(linecount, "N").Interior.Color = RGB(255, 255, 64)
               .Cells(linecount, "O").Interior.Color = RGB(255, 255, 64)
            Else
            End If
            linecount = linecount + 1
        Next i
    End With
End Sub