【发布时间】:2015-03-19 05:14:42
【问题描述】:
人们参加了一项调查,他们的回答最终在 Excel 电子表格中的一行中出现。人们进行多项调查,因此他们的回答分布在多个工作表中。这些人在每次调查之前都有自己使用的 ID。
我想遍历每个工作表中的行,并从具有特定人员调查回复的行中复制某些单元格。假设是将响应拉入一个电子表格的人知道 ID。
Sub CreateSPSSFeed()
Dim StudentID As String ' (StudentID is a unique identifier)
Dim Tool As Worksheet ' (this is the worksheet I'm pulling data into)
Dim Survey1 As Worksheet ' (this is the sheet I'm pulling data from)
Dim i As Integer ' (loop counter)
Tool = ActiveWorkbook.Sheets("ToolSheet")
Survey1 = ActiveWorkbook.Sheets("Survey1Sheet")
' (This is how the loop knows what to look for)
StudentID = Worksheet("ToolSheet").Range("A2").Value
ActiveWorksheet("Survey1").Select ' (This loop start with the Survey1 sheet)
For i = 1 to Rows.Count ' (Got an overflow error here)
If Cells (i, 1).Value = StudentID Then
'!Unsure what to do here-- need the rest of the row
' with the matching StudentID copied and pasted
' to a specific row in ToolSheet, let's say starting at G7!
End If
Next i
End Sub
我在这里进行了研究,但在将循环与跨表移动相结合时运气不佳。
【问题讨论】:
-
你指的是溢出吗?如果是这样,请知道我正在使用的行数不会超过几百。
-
@pnuts 是对的。长用。
Rows.Count2003 年约为 65K,2007 年及以上约为 1M。即使你没有走那么远,编译器已经在实际运行程序之前检查你的变量是否可以处理它。
标签: excel vba copy-paste