2017-08-03 37 views
1

enter image description here 大腦融化。我知道Stackoverflow不會做免費編碼,但我堅持如何開始。我試圖從左側過濾和輸出數據,看起來像使用VBA腳本的右側數據。任何有關我如何完成此任務的建議?故障篩選,輸出和短接此數據

+0

(1)從第一個記錄中讀取源名稱,在目標名稱中搜索它。如果找不到,請將名稱添加到目標名稱。 (2)在目標名稱中找到源名稱(現在肯定會在那裏),如果相應的源列是「x」,則將其他列更新爲「x」。(3)重複下一條記錄。 (有可能更簡單的方法來做到這一點,但我餓了,而不是現在直截了當。) – YowE3K

回答

0

這可能讓你開始:

Sub mergeCategoryValues() 
    Dim lngRow As Long 

    With ActiveSheet 
     Dim columnToMatch As Integer: columnToMatch = 2 
     Dim columnToConcatenate As Integer: columnToConcatenate = 4 
     Dim columnToSum As Integer: columnToSum = 5 

     lngRow = .Cells(65536, columnToMatch).End(xlUp).Row 
     .Cells(columnToMatch).CurrentRegion.Sort key1:=.Cells(columnToMatch), Header:=xlYes 

     Do 
      If .Cells(lngRow, columnToMatch) = .Cells(lngRow - 1, columnToMatch) Then 
       .Cells(lngRow - 1, columnToConcatenate) = .Cells(lngRow - 1, columnToConcatenate) & .Cells(lngRow, columnToConcatenate) 
       .Cells(lngRow - 1, columnToSum) = .Cells(lngRow - 1, columnToSum) + .Cells(lngRow, columnToSum) 
       .Rows(lngRow).Delete 
      End If 

      lngRow = lngRow - 1 
     Loop Until lngRow = 1 
    End With 
End Sub 

是這個代碼改編:Excel VBA - Combine rows with duplicate values in one cell and merge values in other cell
所有你需要搞清楚的是,除去第一列,使變量更有活力。讓我知道這是否有幫助。

+0

這是完美的...太好了... –

+0

很高興我能幫忙,祝你有美好的一天。 –