程序问答   发布时间:2022-05-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了将 m x n 数组的条目转换为列表大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决将 m x n 数组的条目转换为列表?

开发过程中遇到将 m x n 数组的条目转换为列表的问题如何解决?下面主要结合日常开发的经验,给出你关于将 m x n 数组的条目转换为列表的解决方法建议,希望对你解决将 m x n 数组的条目转换为列表有所启发或帮助;

对于会计导出文件,我试图从 m x n 数组中创建一个金额列表(参见底部的图片 1)。目标是为 B10:K27 中输入的每个金额创建一个条目。此条目还应分别包含其相应的代码第 9 行和 A 列。

将 m x n 数组的条目转换为列表

因此,C7 中条目的导出表中的输出行(单元格 A1:C1)应为:

4,00 ;第219话12350

问题:我设法定义了范围并将实际金额输入到我的导出列表中,但是无论我尝试什么,我都不知道如何“选择”当前适用的行和适用的列的值目前正在通过“For Each importcell In importrange.cells”进行处理,以便我可以粘贴它。这是我当前的代码:

Option Explicit

Public Sub AddToimportSheet()

Dim lastrow As Long
Dim lastcol As Long
Dim importrange As Range
Dim importcell As Range
Dim outputrange As Range
Dim outputrow As Long
Dim outputcol As Long

lastrow = Sheet1.Range("A9").End(xlDown).Row
lastcol = Sheet1.Cells(9,columns.Count).End(xlToleft).column

Set importrange = Sheet1.Range(Sheet1.Cells(9 + 1,1 + 1),Sheet1.Cells(lastrow,lastcol))

outputrow = 1
outputcol = 1

Set outputrange = Sheet2.Range(Sheet2.Cells(outputrow,outputcol),Sheet2.Cells(outputrow,outputcol))

For Each importcell In importrange.Cells
    If importcell <> 0 And IsNumeric(importcell) = True Then
        Sheet2.Range(Sheet2.Cells(outputrow,outputcol)) = importcell.Value
        outputrow = outputrow + 1
    Else
    End If
Next importcell

End Sub

非常感谢任何帮助。谢谢。

Input-Sheet

解决方法

下面的代码应该可以完成这项工作。请尝试一下。

Sub AppendToExportSheet()
    ' 160
    
    Dim SrcRng          As Range                ' soure data range
    Dim Src             As Variant              ' source data
    Dim C               As Long                 ' loop counter: columns
    Dim R               As Long                 ' loop counter: rows
    Dim Output          As Variant              ' data of one row
    Dim Ro              As Long                 ' target row for Output
    
    With Sheet1
        Set SrcRng = .Range(.Cells(9,1),.Cells(9,.columns.Count).End(xlToLeft))
        ' the column title is 0                 ' change to suit
        Set SrcRng = SrcRng.Find(0,xlValues,xlWholE)
        If (SrcRng Is Nothing) Or (SrcRng.column = 1) Then
            MsgBox "Sub@R_510_10586@l column not found.",vbInformation,"ProgrAMMing error"
            Exit Sub
        End If
        Set SrcRng = .Range(.Cells(9,.Cells(.Rows.Count,1).End(xlUp)) _
                            .Resize(,SrcRng.column)
        Src = SrcRng.Value
        ' Debug.Print SrcRng.Address
    End With
    
    Application.Screenupdating = false          ' less work: run faster
    With Sheet2
        Ro = .Cells(.Rows.Count,1).End(xlUp).Row
        For R = 1 To UBound(SrC)
            If Val(Src(R,UBound(Src,2))) Then ' if sub@R_510_10586@l has a value <> 0
                ReDim Output(1 To 3)
                Output(1) = Src(R,2))
                Output(3) = Src(R,1)
                For C = 2 To UBound(Src,2)
                    If Val(Src(R,C)) Then
                        Output(2) = Src(1,C)
                        Exit For
                    End If
                Next C
                Ro = Ro + 1
                .Cells(Ro,1).Resize(1,UBound(Output)).Value = Output
            End If
        Next R
    End With
    Application.Screenupdating = True
End Sub

代码检查小计列,如果有值则创建一个条目。这种方法有很多含义。首先,它通过搜索标题 0 来找到该列。如果在现实生活中它不是 0,则更改标准。其次,它忽略“委员会 2”部分中的任何数据。从那里提取数据不是您问题的一部分,但要从那里添加数据只需要在开头重新配置 SrcRng,然后遍历代码第二部分中的部分。

大佬总结

以上是大佬教程为你收集整理的将 m x n 数组的条目转换为列表全部内容,希望文章能够帮你解决将 m x n 数组的条目转换为列表所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:mnx