删除行并在声明为Variant的范围中插入行

我必须通过完整的A列,并检查单元格值是否小于6,然后删除它。

我曾经像这样在表单上执行操作

activesheet.range("A" & row_number).select selection.entirerow.delete 

正如人们build议使用变体,我想与变体一起工作。

我已经把一组范围变成了一个变体。

  dim var as variant var=sheet1.range("A1:D1000").value 

假设我有20行的A列的单元格长度小于6的行。我必须删除variablesvariables中的这20行,包括variablesB,C,D中的其他相应列。我的意思是var(“A18 :D18“)应该被完全删除。

我听说有人说我们不能从一个变体中删除一个条目,我们应该采取一个新的变体,只复制这些值到新的变体。 如果是这种情况,我如何将一个变体复制到另一个变体?

对于其A列单元格值长度大于6的行,应将单元格值转换为标准格式。 我已经使用表单来完成了

 activesheet.cells("some cell!).value=activesheet.cells("").value 

我循环遍历每一行,并且每次我敲数据表时都花费一些时间。 我现在要使用变体,取整个范围,执行操作并将其写回。

如何删除我们inputvariables的完整行像var(“A2:D2”),然后将var(“A4:D4”)值复制到var2(“A6:D6”)等其他变体?

我们是否也可以在变体的中间插入一个变体,就像我们在表单中插入行一样?

像这样的东西

  1. 在第一张工作表(数组X)上需要A1:D1000
  2. testing每一列一个单元格,看它是否长于6个字符
  3. 如果它大于6,那么整个行(在你的情况下是4个单元格)被写为Y的新行
  4. 缩小的数组写入到sexcond工作表的A1中
  5. 将sheet1列的格式添加到sheet2列

     Sub VarExample() Dim ws1 As Worksheet Dim ws2 As Worksheet Set ws1 = ActiveWorkbook.Sheets(1) Set ws2 = ActiveWorkbook.Sheets(2) Dim X Dim Y Dim lngRow As Long Dim lngCOl As Long Dim lngCnt As Long 'define the size of the array to be processed on sheet 1 X = ws1.Range("A1:D1000").Value2 'make the second array the same size as the first ReDim Y(1 To UBound(X, 1), 1 To UBound(X, 2)) 'Look at the first record in each row [,1] part to see if it is longer than 6 chars For lngRow = 1 To UBound(X, 1) If Len(X(lngRow, 1)) > 6 Then 'Longer than 6 so add 1 more row to the length of the 2nd array lngCnt = lngCnt + 1 'Loop through value in this row of the first array and place in the second array For lngCOl = 1 To UBound(X, 2) Y(lngCnt, lngCOl) = X(lngRow, lngCOl) Next lngCOl End If Next 'create a range on the second sheet equal in size to the second array and dump the array to it ws1.[a1].Resize(UBound(Y, 1), UBound(Y, 2)).Value2 = Y 'copy formatting ws1.[a1].Resize(1, UBound(X, 2)).EntireColumn.Copy ws2.[a1].Resize(1, UBound(X, 2)).EntireColumn.PasteSpecial Paste:=xlPasteFormats Application.CutCopyMode = False End Sub