Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays '的动态行和静态列数组;写行';环_Arrays_Vba_Excel - Fatal编程技术网

Arrays '的动态行和静态列数组;写行';环

Arrays '的动态行和静态列数组;写行';环,arrays,vba,excel,Arrays,Vba,Excel,我需要为“写行”自定义函数生成一个数组。此函数用于在循环期间将一行单元格(数组)写入文本文件。 此数组的大小是静态的。 要写入文本文件的行被下面的Rng变量“检测到”: Set Rng = Worksheets("Sheet1").Columns(5).Find(userform1.ComboBox1.Value) i、 e.Rng变量仅为第5列中的单个单元格编制索引-与ComboBox1中的值匹配。writeLine要写入的数组将是由Rng匹配的行的第6:49列 “write lin

我需要为“写行”自定义函数生成一个数组。此函数用于在循环期间将一行单元格(数组)写入文本文件。
此数组的大小是静态的。
要写入文本文件的行被下面的Rng变量“检测到”:

Set Rng = Worksheets("Sheet1").Columns(5).Find(userform1.ComboBox1.Value)    
i、 e.Rng变量仅为第5列中的单个单元格编制索引-与ComboBox1中的值匹配。writeLine要写入的数组将是由Rng匹配的行的第6:49列

“write line”函数的参数为

  • 组合框的值,即
    userform1.combobox1.value
    ,以及
  • 要在“write line”函数中写入的数组
  • 到目前为止,我有:

    Private Sub CommandButton18_Click()
    
    Dim Range As Range
    Dim Array As Range
    
    Set Range =      Worksheets("Sheet1").Columns(5).Find(userform1.ComboBox1.Value) ''anticipated to set the row index of the array???
    
    Array = ????
    
    Function.writeLine(userform1.ComboBox1.Value,????)
    
    End Sub
    
    我遇到的麻烦是创建一个数组,该数组包含不断变化的行,同时固定列数

    以下是writeLine函数的一部分:

    Do Until objTF.AtEndOfStream
        readString = objTF.readline
        data = Split(readString, vbTab)
        foundID = data(0)
        If StrComp(**foundID, ID**, 1) <> 0 Then
            objTF2.writeLine (readString)
        ElseIf StrComp(**foundID, ID**, 1) = 0 Then
            'write initial value outside the loop
            strTmp = Split(readString, strDelim)
            'Modify the data array to include the data provided by writeArray
            For argPos = 5 To UBound(data)
                'check for index out of bounds, stop writing if it is!
                If (argPos - 5) > UBound(writeArray) Then Exit For 'need to check this will exit if the value is index out of bounds.
                data(argPos) = writeArray(dataPos)
                dataPos = dataPos + 1
            Next argPos
            'Take each entry from data and build a string delimited by strDelim
            Do Until counter > UBound(data)
                resultStr = IIf(counter <= UBound(data), resultStr & data(counter) & strDelim, resultStr & data(counter))
                counter = counter + 1
            Loop
            'output to temp file
            objTF2.writeLine (resultStr)...
    
    Do直到objTF.AtEndOfStream
    readString=objTF.readline
    数据=拆分(读取字符串,vbTab)
    foundID=数据(0)
    如果StrComp(**foundID,ID**,1)0,则
    objTF2.writeLine(读取字符串)
    ElseIf StrComp(**foundID,ID**,1)=0然后
    '在循环外写入初始值
    strTmp=Split(readString,strDelim)
    '修改数据数组以包含writeArray提供的数据
    对于argPos=5到UBound(数据)
    '检查索引是否超出范围,如果超出范围,请停止写入!
    如果(argPos-5)>UBound(writeArray),则为“需要检查”退出,如果值超出索引范围,则将退出。
    数据(argPos)=写入阵列(dataPos)
    dataPos=dataPos+1
    下一个argPos
    '从数据中获取每个条目,并构建一个由strDelim分隔的字符串
    直到计数器>UBound(数据)为止
    
    resultStr=IIf(计数器使用Ubound以数组形式获取范围

    专用子命令按钮18_单击()


    End Sub

    能否提供一些输入示例Hanks newjenn。我第一次没有准确解释我的问题(缺乏vba知识)。行不是如前所述的动态。数组是静态的。更改的是行选择…那么您的代码不需要循环,您可以传递rRange(rowselectionvalue,columnvalue)好的,阅读我的问题可能我没有再次正确解释问题。rRange变量只索引第5列中的单个单元格-与ComboBox1中的值匹配。writeLine要写入的数组将是与rRange匹配的行的第6:49列。这有意义吗?写入行的输入是什么?例如,rRange将获取来自用户的行,该行需要输入到writeline函数中。我已经在原始问题中添加了代码。希望它能有所帮助。
    Dim rRange As Range
    Dim colno As Long
    Dim rownumber As Long
    Dim sString As String
    
        lastrow = 10
    
    For colno = 6 To 43
       For rownumber = 1 To lastrow
           sString = Worksheets("sheet1").Cells(rownumber, colno)
           Next rownumber
        Next