[英]Delete Row if Columns K:R all contain blanks VBA Excel
Bit of a background: I'm trying to copy a table from "Create Form" N2:AE14 背景:我正在尝试从“创建表单” N2:AE14复制表
Set r = Sheets("Create Form").Range("COPYTABLEB")
Selection.Copy
Set dest = Sheets("Sample Data").Range("B1").End(xlDown).Offset(1, 0)
r.Copy
dest.PasteSpecial Paste:=xlPasteValues
I want it to copy only the cells that have values and not blanks but unfortunately it's picking up the formulas and pasting them as blanks. 我希望它仅复制具有值的单元格而不是空格,但不幸的是,它正在拾取公式并将其粘贴为空格。 So when I go to paste the next section in, it sees the blanks as data.
因此,当我要粘贴下一部分时,它将空白视为数据。
So instead I'm trying to figure out a way of deleting an entire Row in "Sample Data" if Columns K:R all contain blanks once its been copied across. 因此,相反,如果列K:R在复制后全部都包含空格,那么我将尝试找出一种删除“样本数据”中整个行的方法。
I currently have a loop that does it for column B being blank but it takes far too long. 我目前有一个循环,它对B列为空白执行此操作,但是它花费的时间太长。
Lastrow = Range("B" & Rows.Count).End(xlUp).Row
MsgBox (Lastrow)
For i = Lastrow To 2 Step -1
If Trim(Range("B" & i).Value) = "" And Trim(Range("B" & i).Value) = "" Then
Range("B" & i).EntireRow.Select
Selection.Delete
End If
Next i
Could someone please help me either: 有人可以帮助我吗:
a.) copy and paste the values across minus all the blanks a。)将值复制并粘贴到减去所有空白处
b.) or help me with a quicker way of deleting the rows? b。)或以更快的方式帮助我删除行?
assuming 假设
"an entire Row in "Sample Data" if Columns K:R all contain blanks"
“如果K:R列均包含空白,则“样本数据”中的整行”
you could try this: 您可以尝试以下方法:
Sub CopyValuesAndDeleteRowsWithBlankKRColumns()
Dim pasteArea As Range
Dim iRow As Long
With Sheets("Create Form").Range("COPYTABLEB")
Set pasteArea = Sheets("Sample Data").Range("B" & Rows.count).End(xlUp).Offset(1, 0).Resize(.Rows.count, .Columns.count)
pasteArea.Value = .Value
End With
With Intersect(pasteArea, Sheets("Sample Data").Range("K:R"))
For iRow = .Rows.count To 1 Step -1
MsgBox WorksheetFunction.CountBlank(.Rows(iRow)) & " - " & WorksheetFunction.CountBlank(.Rows(iRow)) Mod 8
If WorksheetFunction.CountBlank(.Rows(iRow)) Mod 8 = 0 Then .Rows(iRow).EntireRow.Delete
Next
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.