[英]Excel Match Numbers in 2 Columns to a Number in a 3rd
我遇到了一些障礙。 我從會計程序獲得.PDF輸出,然后將數據復制/粘貼到excel中,然后將文本轉換為列。 我正在嘗試將GL代碼與該特定帳戶的總數匹配。 A,B和C列顯示了對數據進行排序之前的狀態,“預期輸出”下的行顯示了我希望如何輸出數據。
我正在嘗試使該過程自動化,因此我可以將數據以原始格式粘貼到A,B和C列中,並以預期輸出的格式自動吐出所需的數字。 GL代碼保持不變,但是數字和行數將改變。 我對它們進行了顏色編碼,以便於檢查。
提前非常感謝您!
結合使用以下公式,您可以創建過濾結果列表。 它在主體上起作用,您要提取的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),因為這可能導致過多的計算。 確保將其限制在您要查看的范圍內。
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.