我有2张excel表。 "进度报告" &安培; "悬疑"
目前我有几行代码可以找到" B&B列中的所有内容。 "进展报告"工作表,如果它包含短语" App Submitted"它将它复制到悬念。
afterGetColHeader: function (col, TH) {
// nothing for first column
if (col == -1) {
return;
}
var instance = this;
// create input element
var input = document.createElement('input');
input.type = 'text';
input.value = TH.firstChild.textContent;
TH.appendChild(input);
Handsontable.Dom.addEvent(input, 'change', function (e){
var headers = instance.getColHeader();
headers[col] = input.value;
instance.updateSettings({
colHeaders: headers
});
});
TH.style.position = 'relative';
TH.firstChild.style.display = 'none';
}
End Sub
但是,我需要运行一个If语句来检查"列B"不包含" App已提交"如果它没有从" Suspense"中删除整行。片。我处于非常初级的编码水平,但我试图让代码按照我的计划工作。我在另一个if语句下添加了这个。我应该把这个函数作为一个新的sub,然后创建一个master sub并调用它们同时运行吗?
Sub CopyNewRow()
Dim c As Range
Dim j As Integer
Dim j1 As Integer
Dim Source As Worksheet
Dim Target As Worksheet
Set Source = ActiveWorkbook.Worksheets("Progress Report")
Set Target = ActiveWorkbook.Worksheets("Suspense")
j = 2
For Each c In Source.Range("B1:B50000") '
If c = "App Submitted" Then
Source.Rows(c.Row).Copy Target.Rows(j)
j = j + 1
End If
Next c
我不介意阅读与此主题相关的文章,因为我想学习如何更自信地编写视觉基础编码,但是,我不确定如何解决这个问题。
答案 0 :(得分:0)
如果你有一个唯一的ID,那么更容易识别需要从Suspense表中删除哪一行,但下面的代码将是什么,循环进度报告并在复制行之前清除Suspense上的所有内容将“App Submitted”提交给Suspense:
Sub CopyNewRow()
Dim c As Range
Dim j As Integer
Dim j1 As Integer
Dim Source As Worksheet: Set Source = Worksheets("Progress Report")
Dim Target As Worksheet: Set Target = Worksheets("Suspense")
Dim LastRow As Long
Dim LastRow2 As Long
LastRow = Source.Cells(Source.Rows.Count, "B").End(xlUp).Row
'check how many rows with data on Column B of Source sheet
Target.Rows("2:" & Rows.Count).ClearContents
'delete everything on Suspense before copying App Submitted across
For i = 2 To LastRow
If Source.Cells(i, 2) = "App Submitted" Then
LastRow2 = Target.Cells(Target.Rows.Count, "A").End(xlUp).Row
'check the last row with data on Suspense
'Source.Rows(i).Copy Target.Rows(LastRow2 + 1) 'copy to next free row on Suspense
Target.Cells(LastRow2 + 1, 1) = Source.Cells(i, 1)
Target.Cells(LastRow2 + 1, 2) = Source.Cells(i, 2)
'above copy cells 1 & 2, (ie, A & B) from Source into Target
End If
Next i
End Sub