Excel VBA偏移复制粘贴
问题描述:
希望你做得很好。我将在前言中说我不是程序员,我确信我已经开始的代码充满了更多的错误,然后我认为。希望你能帮助:D。Excel VBA偏移复制粘贴
我有被从出来这样的其他程序生成的Excel表:
然而,这种纸的大小可随每一代新此表从其他程序更改。 (例如,下一次A可以有7个,D可以有9个)并且由于我只需要特定时间的特定信息组,因此不能很容易地使用该表来完成所需的数学运算,在这个例子中,组B和只有D。
什么,我希望创造的东西,将采取该纸张,作为其生成,并把它变成的东西,看起来像这样:
这是我写这样的代码很远,但因为我不知道自己在做什么,所以我一直在遇到很多问题。任何帮助,将不胜感激。
Option Explicit
Sub Numbers()
Dim matchesFound As Integer
Dim row As Integer
Dim c As Integer
Dim copyRow As Integer
Dim copyLocationColumn As Integer
Dim arr(2) As String
arr(0) = "1"
arr(1) = "2"
arr(2) = "3"
Function arrayContainsValue(array, varValue)
found = false
for each = 0 to array
if array(i) = varValue then
found = true
exit for
arrayContainsValue = found
End Function
row = 1
c = 1
copyLocationColumn = 1
copyRow = 1
matchesFound = 0
Do While matchesFound < 3
if arrayContainsValue(arr, ThisWorkbook.Sheets("Data").Cell(column,row))
matchesFound = matchesFound + 1
Do While ThisWorkbook.Sheets("Data").Cell(column, row)
ThisWorkbook.Sheets("postHere").Cell(copyLocationColumn, copyRow) = _
ThisWorkbook.Sheets("postHere").Cell(c + 1, row)
copyRow = copyRow+1
row = row + 1
Loop
End If
row = row + 1
Loop
End Sub
答
有一条注释许多逻辑错误且具,Excel中突出显示它们自动我会做一个总结解释一下:
1.功能不能“在中间”的分,光洁度Sub(从子函数中取出并粘贴,直到它说明结束为止)
2.array是一个禁止的名字,用另一个变量名尝试
3.For每个= 0?到数组?你试图表示什么对于每一个都必须是元素对于Array中的每个元素例如For和To是用数字定义的东西(对于counter = 1到15)
Function arrayContainsValue(***array***, varValue) '2nd problem
found = false
for each = 0 to array '3rd problem
if array(i) = varValue then
found = true
exit for
arrayContainsValue = found
End Function
.... 4.你错过了一个,然后在年底
if arrayContainsValue(arr, ThisWorkbook.Sheets("Data").Cell(column,row))
我没有得到有关如何涉及到这个问题的编码逻辑陈述(?)