2016-10-08 18 views
-1

我使用'user3598756'幫助下面的代碼。 代碼指示最小銷售值並指示供應商名稱(一個名稱一列)。 我需要按數字順序排列數值,前十位,後9位等等,最小值爲5. 還需要在一個單元格中僅獲取供應商的第一個姓氏。最小值的訂單值e從供應商處得到姓氏和名字

現在是這樣的: https://i.imgsafe.org/8f0c36ee2b.jpg

Link to file

代碼:

Option Explicit 

Sub best() 
Dim copyrow As Long 
Dim helpRng As Range 

copyrow = 30 
With Worksheets("Resumo") 
    With .Range("J11:J47") 
     Set helpRng = .Offset(, .Parent.UsedRange.Columns.Count) 
     helpRng.Value = .Value 
     helpRng.Offset(, 1).Value = .Offset(, -7).Value 
     Set helpRng = helpRng.Resize(.Rows.Count + 1, 2).Offset(-1) 
    End With 
End With 

With helpRng 
    .Cells(1, 1).Resize(, 2) = "header" 
    .Sort key1:=helpRng, order1:=xlAscending, Header:=xlYes 
    .AutoFilter field:=1, Criteria1:=">0" 
    If Application.WorksheetFunction.Subtotal(103, .Resize(, 1)) > 1 Then 
     Worksheets("os melhores").Cells(copyrow, "F").Resize(5, 2).Value = .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Resize(5).Value 
     Worksheets("os melhores").Cells(copyrow, "G").Resize(5).TextToColumns DataType:=xlDelimited, ConsecutiveDelimiter:=True, Space:=True 
    End If 
    .Parent.AutoFilterMode = False 
    .ClearContents 
End With 
End Sub 

我還沒有這個必要的技能來管理做到這一點。 在此先感謝!

+0

顯示輸出多麼渴望應該再次 – user3598756

回答

1

如果我正確理解你的目標,試試這個代碼:

Option Explicit 

Sub worst() 
    Dim copyrow As Long 
    Dim helpRng As Range, copyRng As Range 

    With Worksheets("Resumo") 
     With .Range("J11:J47") 
      Set helpRng = .Offset(, .Parent.UsedRange.Columns.Count) 
      helpRng.Value = .Value 
      helpRng.Offset(, 1).Value = .Offset(, -7).Value 
      Set helpRng = helpRng.Resize(.Rows.Count + 1, 2).Offset(-1) 
     End With 
    End With 

    copyrow = 30 
    Set copyRng = Worksheets("os melhores").Cells(copyrow, "J").Resize(5, 2) 
    With helpRng 
     .Cells(1, 1).Resize(, 2) = "header" 
     .Sort key1:=helpRng, order1:=xlAscending, Header:=xlYes 
     .AutoFilter field:=1, Criteria1:=">0" 
     If Application.WorksheetFunction.Subtotal(103, .Resize(, 1)) > 1 Then 
      copyRng.Value = .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Resize(5).Value 
      copyRng.Sort key1:=copyRng.Cells(1, 1), order1:=xlDescending, Header:=xlNo 
      Application.DisplayAlerts = False 
      copyRng.Columns(2).TextToColumns DataType:=xlDelimited, ConsecutiveDelimiter:=True, Space:=True 
      Application.DisplayAlerts = True 
      copyRng.Offset(, -1).Resize(, 1).FormulaR1C1 = "=CONCATENATE(RC[2], "" "", OFFSET(RC[1],,COUNTA(RC[2]:RC" & .Parent.Columns.Count & ")))" 
      copyRng.Value = copyRng.Value 
     End If 
     .Parent.AutoFilterMode = False 
     .ClearContents 
    End With 
End Sub 
+0

感謝。就像那樣,但是現在,運行代碼時,正在形成一個msgbox,它說'已經是這裏了。你想取代它'是可以阻止這從apearing?代碼在單元格中留下了公式,不能通過vba完成,因爲用戶看不到代碼?謝謝。 – Car

+0

這只是在導致該msgbox的那一行之前添加Application.DisplayAlerts = False語句,然後在它之後恢復「Application.DisplayAlerts = True」。查看編輯的代碼。如果我完成了您的問題,請將答案標記爲已接受。謝謝 – user3598756

+0

嗨,對不起,最近的回覆,但我沒有互聯網。現在它在供應商名稱中給出錯誤#NAME。值是OK。我注意到代碼有另一種語言(我認爲)。 – Car

相關問題