I have the following in Excel spreadsheet,
我在Excel电子表格中有以下内容,
How do I delete a row based on the published within the J column = 0?
如何根据J column = 0中发布的行删除行?
It would be better to cut the row and paste it within another sheet.. but IF you can help me with just deleting it, that would be good.
最好是剪切行并将其粘贴到另一张纸中..但如果你可以帮我删除它,那就太好了。
2 个解决方案
#1
3
This code autofilters the rows on the activesheet where J =0, copies them to the first blank row on the second worksheet, then deletes the rows from the activesheet.
此代码自动过滤活动表上J = 0的行,将它们复制到第二个工作表上的第一个空行,然后从活动表中删除行。
Change this line Set ws2 = Sheets(2)
to copy the rows to a different sheet, ie Set ws2 = Sheets("Your Sheet Name")
or Set ws2 = Sheets(5)
for the fifth sheet etc
更改此行设置ws2 = Sheets(2)将行复制到另一个工作表,即Set ws2 = Sheets(“Your Sheet Name”)或Set ws2 = Sheets(5)表示第五个工作表等
Sub MoveEm()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Set ws1 = ActiveSheet
Set ws2 = Sheets(2)
Dim rng1 As Range
Application.ScreenUpdating = False
With ws1
.AutoFilterMode = False
.Columns("j").AutoFilter Field:=1, Criteria1:="0"
With .AutoFilter.Range.Offset(1, 0).EntireRow
Set rng1 = ws2.Cells.Find("*", ws2.[a1], xlValues, , xlRows, xlPrevious)
If rng1 Is Nothing Then
Set rng1 = ws2.[a1]
Else
Set rng1 = ws2.Cells(rng1.Row + 1, "A")
End If
.Copy rng1
.Delete
End With
.AutoFilterMode = False
End With
Application.ScreenUpdating = True
End Sub
#2
3
Sub Delete_Zero_Codes() ' Deletes The Zero Codes
Dim rCell As Range
Dim strAddress As String
Application.ScreenUpdating = False
With Thisworkbook.Sheets("sheetname").Columns("J")
Set rCell = .Find(What:=0, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByColumns)
If Not rCell Is Nothing Then
Do
strAddress = rCell.Address
rCell.EntireRow.Delete
Set rCell = .FindNext(Range(strAddress))
Loop Until rCell Is Nothing
End If
End With
Application.ScreenUpdating = True
End Sub
These macro deletes zero codes of J column and does not paste them to other sheet, if you need zero codes of J column to be copied to other sheet then let me know i will update it
这些宏删除了J列的零代码,并没有将它们粘贴到其他工作表,如果你需要将J列的零代码复制到其他工作表,那么让我知道我会更新它
#1
3
This code autofilters the rows on the activesheet where J =0, copies them to the first blank row on the second worksheet, then deletes the rows from the activesheet.
此代码自动过滤活动表上J = 0的行,将它们复制到第二个工作表上的第一个空行,然后从活动表中删除行。
Change this line Set ws2 = Sheets(2)
to copy the rows to a different sheet, ie Set ws2 = Sheets("Your Sheet Name")
or Set ws2 = Sheets(5)
for the fifth sheet etc
更改此行设置ws2 = Sheets(2)将行复制到另一个工作表,即Set ws2 = Sheets(“Your Sheet Name”)或Set ws2 = Sheets(5)表示第五个工作表等
Sub MoveEm()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Set ws1 = ActiveSheet
Set ws2 = Sheets(2)
Dim rng1 As Range
Application.ScreenUpdating = False
With ws1
.AutoFilterMode = False
.Columns("j").AutoFilter Field:=1, Criteria1:="0"
With .AutoFilter.Range.Offset(1, 0).EntireRow
Set rng1 = ws2.Cells.Find("*", ws2.[a1], xlValues, , xlRows, xlPrevious)
If rng1 Is Nothing Then
Set rng1 = ws2.[a1]
Else
Set rng1 = ws2.Cells(rng1.Row + 1, "A")
End If
.Copy rng1
.Delete
End With
.AutoFilterMode = False
End With
Application.ScreenUpdating = True
End Sub
#2
3
Sub Delete_Zero_Codes() ' Deletes The Zero Codes
Dim rCell As Range
Dim strAddress As String
Application.ScreenUpdating = False
With Thisworkbook.Sheets("sheetname").Columns("J")
Set rCell = .Find(What:=0, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByColumns)
If Not rCell Is Nothing Then
Do
strAddress = rCell.Address
rCell.EntireRow.Delete
Set rCell = .FindNext(Range(strAddress))
Loop Until rCell Is Nothing
End If
End With
Application.ScreenUpdating = True
End Sub
These macro deletes zero codes of J column and does not paste them to other sheet, if you need zero codes of J column to be copied to other sheet then let me know i will update it
这些宏删除了J列的零代码,并没有将它们粘贴到其他工作表,如果你需要将J列的零代码复制到其他工作表,那么让我知道我会更新它