将范围对象用于循环

时间:2019-05-28 13:57:37

标签: excel vba

我正在搜索某个标头并将其另存为远程对象(FindEQ4)。现在,我想将此标头用作动态范围对象的起点。我的问题是,我如何获取标题5中的标题1的信息并像Set TestR = .Range("C" & 5 + x)那样使用它?

 Sub FindCopyPasteV3()

    With Worksheets("Sheet1").Range("A:FF")

        Dim FindEQ4 As Range
        Dim TestR As Range
        Dim x As Long

        Set FindEQ4 = .Find(What:="Header 1", LookAt:=xlWhole, MatchCase:=True, SearchFormat:=False)

        'I'm looking for something like TestR = .Range("FindEQ4" + x)  
        'which works like Set TestR = .Range("C" & 5 + x) 

    End With

End Sub

enter image description here

2 个答案:

答案 0 :(得分:2)

.Column对象使用.RowRange属性:

Option Explicit
Sub test()

    Dim FindEQ4  As Range
    Dim StartRow As Long
    Dim StartColumn As Long
    Dim TestR As Range

    With ThisWorkbook.Sheets("Sheet1")
        Set FindEQ4 = .Range("A1")
        StartRow = FindEQ4.Row + 1
        StartColumn = FindEQ4.Column
        Set TestR = .Cells(StartRow, StartColumn) 'A2
    End With

End Sub

答案 1 :(得分:1)

使用reader.readAsDataURL(file); .对象的<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Hi</title> </head> <body> <div id="dropZone" style="width: 100px; height: 100px; background-color: red"> <div><ul id="image_bar"></ul></div> </div> <script> var dropZone = document.getElementById('dropZone'); dropZone.addEventListener('dragover', function(e) { e.stopPropagation(); e.preventDefault(); e.dataTransfer.dropEffect = 'copy'; }); dropZone.addEventListener('drop', function(e) { e.stopPropagation(); e.preventDefault(); var files = e.dataTransfer.files; for (var i=0, file; file=files[i]; i++) { if (file.type.match(/image.*/)) { var reader = new FileReader(); reader.onload = function(e2) { // finished reading file data. var img = document.createElement('img'); img.src= e2.target.result; document.getElementById('image_bar').appendChild(img); } reader.readAsDataURL(file); } } }); </script> </body> </html> 属性。

https://docs.microsoft.com/en-us/office/vba/api/excel.range.offset

这将返回一个与原始偏移指定量的范围。第一个参数是要偏移的行数(向下,正负向上),第二个参数是要偏移的列数(向右边,负负)。

例如

Offset代表“ F4”,向上3行,右侧2列。

Range