我遇到了一些障碍。我从会计程序获得.PDF输出,然后将数据复制/粘贴到excel中,然后将文本转换为列。我正在尝试将GL代码与该特定帐户的总数匹配。 A,B和C列显示了对数据进行排序之前的状态,“预期输出”下的行显示了我希望如何输出数据。
我正在尝试使此过程自动化,因此我可以将数据以原始格式粘贴到A,B和C列中,并以预期输出的格式自动吐出所需的数字。 GL代码保持不变,但是数字和行数将改变。我对它们进行了颜色编码,以便于检查。
非常感谢您!
答案 0 :(得分:1)
使用以下公式的组合,您可以创建过滤结果列表。它在主体上起作用,您要提取的Data1文本是唯一带有“-”的文本,并且从Data2和Data3提取的总数是该列中唯一的数字。对该模式的任何更改很可能会破坏系统。请注意,公式不会复制格式。
让我们假设输出将放置在一个小表中,其中E2为左上数据位置。
在E2中,使用以下公式并根据需要向下复制:
=IFERROR(INDEX(A:A,AGGREGATE(15,6,ROW($A$1:$A$30)/ISNUMBER(FIND("-",$A$1:$A$30)),ROW(A1))),"")
在F2中,使用以下公式并根据需要复制到右侧的1列并向下复制:
=IFERROR(INDEX(B:B,AGGREGATE(15,6,ROW($A$1:$A$30)/ISNUMBER(B$1:B$30),ROW(A1))),"")
AGGREGATE执行类似数组的计算。因此,请勿在其中使用完整的列引用(例如A:A),因为这可能导致过多的计算。确保将其限制在您要查看的范围内。
答案 1 :(得分:0)
Try this procedure:
Public Sub bruce_wayne()
'Assumptions
'1. Data spreadsheet will ALWAYS have the structure shown in the question
'2. The key word "Total" (or whatever else it might be) is otherwise NOT found
' anywhere else in the 1st data column
'3. output is written to the same sheet as the data
'4. As written, invoked when data sheet is the active sheet
'5. set the 1st 3 constants to the appropriate values
Const sData2ReadTopLeft = "A1" 'Top left cell of data to process
Const sData2WriteTopLeft = "J2" 'Top left cell of where to write output
Const sSearchText = "Total" 'Keyword for summary data
'*******************
Const sReplaceText = "Wakanda"
Dim r2Search As Range
Dim sAccountCode As String
Dim rSearchText As Range
Dim iRowsProcessed As Integer
Set r2Search = Range(sData2ReadTopLeft).EntireColumn
sAccountCode = Range(sData2ReadTopLeft).Offset(1, 0).Value
iRowsProcessed = 0
Do While Application.WorksheetFunction.CountIf(r2Search, sSearchText) > 0
Set rSearchText = r2Search.Find(sSearchText)
Range(sData2WriteTopLeft).Offset(iRowsProcessed, 0) = sAccountCode
Range(sData2WriteTopLeft).Offset(iRowsProcessed, 1) = rSearchText.Offset(0, 1).Value
Range(sData2WriteTopLeft).Offset(iRowsProcessed, 2) = rSearchText.Offset(0, 2).Value ' add this if there are more summary columns to return
'last two lines could be collapsed into a single line; at the expense of readability..
rSearchText.Value = sReplaceText 'so that next search will find the next instance of the trigger text
iRowsProcessed = iRowsProcessed + 1
sAccountCode = rSearchText.Offset(1, 0).Value
Loop
r2Search.Replace what:=sReplaceText, Replacement:=sSearchText
End Sub