如果列G
=“X”,如何将列A
的单元格值复制到另一个工作表?
当我添加或删除任何X时,我希望这些值能够使下拉列表保持最新状态。下拉列表当前根据工作表2中的内容动态更新。
由于
答案 0 :(得分:1)
这将复制专栏" G"来自' Sheet1'的单元格值到' Sheet2'如果列中的值" A"同一行中的单元格包含" X"。
Option Explicit
Sub CopyGCellVals()
Dim sht1 As Worksheet, sht2 As Worksheet
Dim i as Integer, lastRow As Integer, sht2Row As Integer
sht2Row = 1
Set sht1 = Worksheets("Sheet1")
Set sht2 = Worksheets("Sheet2")
With sht1
lastRow=.Cells(.Rows.Count, "A").End(xlUp).Row
For i=1 to lastRow
If .Cells(i,"A")="X" Then
sht2.Cells(sht2Row,"G") = .Cells(i,"G")
sht2Row = sht2Row + 1
End If
Next
End With
End Sub
答案 1 :(得分:0)
马特,看看是否有效
Dim sheetOrigin As Worksheet
sheetOrigin = Worksheets("Name of your origin worksheet")
Dim sheetDestination as worksheet
sheetDestination = worksheets("Name of your destination worksheet")
dim columnA as range
Set columnA = Range("A:A")
dim columnG as range
Set columnG = Range("G:G")
Dim cell as Range
For Each cell In columnA
If cell.Value = "X" Then
sheetOrigin.columnG.Select
Selection.Copy
sheetDestination.columnA.PasteSpecial xlPasteAll
End If
Next cell
答案 2 :(得分:0)
我不能以低于50的声誉发表评论,所以不幸的是它会显示为"答案"我想。
Amorpheuses的答案很棒,但我的问题非常相似,我想加入这个对话。 OP只需要从一张纸复制到另一张纸。我的问题如下;
*我总共有13张(" Master",然后是" MCL01"" MCL02"" MCL03"等一直到" MCL12")。我需要将通过下拉列表分类的每一行复制到相应的表格中。
例如,如果一行数据被分类为" MCL01",我需要将该行复制到工作表" MCL01",如果是一行数据被归类为" MCL07"我需要将该行复制到工作表" MCL07"等等。*
根据上面Amorpheuses答案中已经编写的代码,我需要多少个整数变量?