【发布时间】:2020-12-29 12:48:59
【问题描述】:
我需要这样的东西。 This picture contains all what I need, I need to insert Automatically the Value column. 我将从对行进行排序开始,以帮助我将相同的值影响到相同的行。 我需要逐行比较(行到下一行),如果相同,我会影响它们相同的值(列值)。
Sub SortMultipleColumns()
// I'll start by sorting rows, to help me to affect the same value to the same rows
With ActiveSheet.Sort
.SortFields.Clear
.SortFields.Add Key:=Range("A1"), Order:=xlAscending
.SortFields.Add Key:=Range("B1"), Order:=xlAscending
.SortFields.Add Key:=Range("C1"), Order:=xlAscending
.SortFields.Add Key:=Range("D1"), Order:=xlAscending
.SetRange Range("A1", Range("D1").End(xlDown))
.Header = xlYes
.Apply
End With
Dim bothrows As Range, i As Integer
Set bothrows = Selection
With bothrows
// here i need to compre rows and insert in the last column value start by 1++
For i = 1 To .Rows.Count
If Not StrComp(.Cells(1, i), .Cells(2, i), vbBinaryCompare) = 0 Then
// here I need to do something
End If
Next i
End With
End Sub
【问题讨论】: