我对VBA非常陌生,如果一个小区有一个"是"我试图写一些会复制整行的东西。在里面。
源位于名为" Master List"的工作表上。目标工作表被称为" CE Class"
如果F列有"是"然后从"主列表"中复制行。并把它放在" CE Class"从第4行开始。
答案 0 :(得分:0)
根据您提供的说明,这样的事情应该适合您。我评论了代码,试图弄清楚它在做什么以及为什么。
Sub tgr()
'Declare variables
Dim wb As Workbook
Dim wsData As Worksheet
Dim wsDest As Worksheet
Dim rCopy As Range
Dim FCell As Range
'Assign object variables
Set wb = ActiveWorkbook
Set wsData = wb.Sheets("Master List")
Set wsDest = wb.Sheets("CE Class")
'Loop through each cell in column F
For Each FCell In wsData.Range("F1", wsData.Cells(wsData.Rows.Count, "F").End(xlUp)).Cells
'Check if the F Cell's value is "yes"
If Trim(LCase(FCell.Value)) = "yes" Then
'Found a "yes", add it to rCopy
If rCopy Is Nothing Then
Set rCopy = FCell
Else
Set rCopy = Union(rCopy, FCell)
End If
End If
Next FCell
'Check if there is any data to copy over
If Not rCopy Is Nothing Then
'There is data to copy, clear the old results
wsDest.Range("A4", wsDest.Cells(wsDest.Rows.Count, "A")).EntireRow.Clear
'Copy over the data
rCopy.EntireRow.Copy wsDest.Range("A4")
End If
End Sub
答案 1 :(得分:0)
您不必使用VBA,只需转到所需的单元格并粘贴逻辑命令即可。
= IF(F1 = “是”,masterlist!A1)
仅供参考:该命令也适用于vba
你也可以玩A1值并看看它是如何工作的