如果满足条件,则向字典添加大范围的值

时间:2018-03-26 15:52:29

标签: excel vba dictionary

我正在尝试根据从第5行开始的第L列中的键到L中的第一个空白单元格将大范围(D:AX)添加到字典中。代码当前设置为从列L获取值和斧头。如何修改此代码以使用L作为键将值D:AX添加到字典中?任何帮助表示赞赏!

renderItem = (item, parentNavigate) => (
    <TouchableOpacity onPress={parentNavigate('Details')} >
        <View style={{width: 136}}>
            ...
            <Text>some text</Text>
        </View>
    </TouchableOpacity>
);

const Strip = (props, parentNavigate) => {
    return Object.keys(props).map(function(key, i) {
        return Object.keys(props[key]).map((strips, i) => {
            var strip = props[key][strips];
            return(
                <View>
                    <Text>{strip.title}</Text>
                    <FlatList horizontal
                        data={strip.someobjects}
                        renderItem={(item, parentNavigate) => this.renderItem(item, parentNavigate)}
                    />     
                </View>
            )
        });
    })
}

1 个答案:

答案 0 :(得分:1)

类似的东西:

Option Explicit

Sub TEST()

    Dim dict As Object
    Dim last As Long

    Set dict = CreateObject("Scripting.Dictionary")

    With ThisWorkbook.Worksheets("Sheet1")

        If .Cells(.Rows.Count, "L").End(xlUp).Row > 5 Then
            last = .Cells(.Rows.Count, "L").End(xlUp).Row
        Else
            last = 5
        End If

        Dim rData As Range

        Set rData = .Range("L5:L" & last & ",AX5:AX" & last)

        Dim i As Long

        For i = rData.Row To rData.Row + rData.Rows.Count - 1

            If Not IsEmpty(.Cells(i, "L")) And Not dict.Exists(.Cells(i, "L").Value) Then

                dict.Add .Cells(i, "L").Value, .Range(.Cells(i, "D"), .Cells(i, "AX")).Value

            End If

        Next i
        ' .Parent.Close False

    Dim columnCount As Long
    columnCount = .Range(.Cells(i, "D"), .Cells(i, "AX")).Columns.Count

    End With

   Dim key As Variant
   Dim counter As Long

   For Each key In dict.keys
       counter = counter + 1
       Worksheets("Sheet2").Range("A" & counter).Resize(1, columnCount) = dict(key)
   Next key

End Sub

如果将值存储为数组而不是范围

 Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")

    Dim Fileout As Object
    Set Fileout = fso.CreateTextFile("C:\Users\User\Desktop\Test\Test.txt", True, True)
    Dim n As Long

    For Each key In dict.keys

        For n = 1 To UBound(dict(key), 2)
          Fileout.WriteLine dict(key)(1, n)
        Next n

    Next key

    Fileout.Close

写出txt文件:

content= fopen('text file.txt');

for i=1:size(content,1) *%loop to read till the end of the matrix* 

    variable_part(i) = fgetl(fid); *%read row and create the integer value in the dynamic variable.*

    for i=1 *% loop through the matrix that contains all the created dynamic variables one by one and perform these.* 
         for i=1:size(variable_part(i),1)
             a= variable_part(i)(i,:);
                variable_part(i,1)= mean(a);
                variable_part(i,2)= min(a);
                variable_part(i,3)= max(a);
                variable_part(i,4)= std(a);
                variable_part(i,5)= var(a);
                variable_part(i,6)= max(a)-min(a);
          end;
     end;
end;