1
新的一天,新的问题。 我收到了很多帮助,并希望你也可以帮助我。已经四处搜寻解决我的问题,但没有找到。使用列索引,如何复制特定列
这里是我的代码:
SearchString = "start"
Set aCell = phaseRange.Find(What:=SearchString, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not aCell Is Nothing Then
Set bCell = aCell
ReDim Preserve arrStart(nS)
arrStart(nS) = aCell.Row
nS = nS + 1
Do While ExitLoop = False
Set aCell = phaseRange.FindNext(After:=aCell)
If Not aCell Is Nothing Then
If aCell.Row = bCell.Row Then Exit Do
ReDim Preserve arrStart(nS)
arrStart(nS) = aCell.Row
nS = nS + 1
Else
ExitLoop = True
End If
Loop
Else
End If
而且写出来:
For i = 1 To nS - 1
Sheets("DataSheet").Select
Sheets("raw_list").Rows(arrStart(i)).Copy
Cells(i, 1).Select
ActiveSheet.Paste
Next
正如你看到的,我在一弦一柱寻求。当我得到结果时,行号存储在一个数组中。在下一个代码片段中,我写出了整行中的命中。是否有可能不是取整行,而是以简单的方式选择要复制的行中哪些列?
感激援助
工程就像一个魅力。谢谢。但试图添加更多的列。试图将其改为.Range,但无法使其工作。 – Andreas 2012-07-06 10:59:11
也尝试与.Union。但它不起作用 'Sheets(“raw_list”)。Union(Cells(arrStart(i),NameCol),Cells(arrStart(i),PhaseCol))。复制' – Andreas 2012-07-06 13:22:44
使用'范围'而不是'联合':) – 2012-07-06 13:42:50