我是编码的新手,需要帮助!我希望这根据是否选择数量将BOMsht中的行始终排在最前面。
我尝试使用下面的代码根据列对行进行排序,但是它将使黑色行保持静止。我希望它从上到下全部排序而没有黑行。
Option Explicit
Sub Pleasepleasework()
Dim i As Long, g As Long, h As Long, j As Long
Dim MediaSht As Worksheet, BOMSht As Worksheet
Dim row As Range
' set the worksheet objects
Set MediaSht = ThisWorkbook.Worksheets("Media")
Set BOMSht = ThisWorkbook.Worksheets("Bill of Materials")
g = 6
h = 4
With MediaSht
For i = 4 To 1000
If .Range("A" & i).Value >= 1 Then
BOMSht.Range("A" & g) = MediaSht.Range("A" & h)
BOMSht.Range("B" & g) = MediaSht.Range("B" & h)
BOMSht.Range("C" & g) = MediaSht.Range("C" & h)
BOMSht.Range("D" & g) = MediaSht.Range("D" & h)
BOMSht.Range("E" & g) = MediaSht.Range("E" & h)
BOMSht.Range("F" & g) = MediaSht.Range("F" & h)
Else
BOMSht.Range("A" & g).ClearContents
BOMSht.Range("B" & g).ClearContents
BOMSht.Range("C" & g).ClearContents
BOMSht.Range("D" & g).ClearContents
BOMSht.Range("E" & g).ClearContents
BOMSht.Range("F" & g).ClearContents
End If
g = g + 1
h = h + 1
Next i
End With
BOMSht.Range("G5") = "Index"
BOMSht.Columns("A:G").Sort key1:=Range("G6"), _
order1:=xlAscending, Header:=xlYes
End Sub
我希望它停止跳过空行并删除它们,以便从顶部开始对行进行排序。