我在' user3598756'的帮助下制作了以下代码。 代码表示最小销售值并伪造供应商名称(按列列出一个名称)。 我需要按降序排序数字,前十个,然后九个等等,最少5个。 还需要在一个单元格中仅获得供应商的第一个姓氏。
现在是这样的: https://i.imgsafe.org/8f0c36ee2b.jpg
代码:
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 :(得分: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