Range1.Value = Range2.Value没有填充

时间:2018-01-10 20:24:58

标签: excel vba excel-vba

我正在尝试将单元格范围移动到一行,但不同的列。我复制/粘贴时代码工作正常,但工作表显着减慢。虽然实际的单元格没有填充,但这种方法似乎工作得更快。代码如下:

lastRow = Cells.Find(What:="*", _
                After:=Range("A1"), _
                LookAt:=xlPart, _
                LookIn:=xlFormulas, _
                SearchOrder:=xlByRows, _
                SearchDirection:=xlPrevious, _
                MatchCase:=False).Row

    For i = 2 To lastRow
        If Cells(i, 4).Value = Cells(i + 1, 4).Value Then                   '1st if
            Debug.Print Cells(i, 4).Value & "  " & Cells(i + 1, 4).Value

            If Cells(i, 4).Value = Cells(i + 2, 4).Value Then           '2nd if
                Debug.Print Cells(i, 4).Value & "    " & Cells(i + 2, 4).Value

                If Cells(i, 4).Value = Cells(i + 3, 4).Value Then       '3rd if
                    Debug.Print Cells(i, 4).Value & "    " & Cells(i + 3, 4).Value

                    If Cells(i, 4).Value = Cells(i + 4, 4).Value Then       '4th if
                        Debug.Print Cells(i, 4).Value & "    " & Cells(i + 4, 4).Value

                        If Cells(i, 4).Value = Cells(i + 5, 4).Value Then       '5th if

                            Debug.Print Cells(i, 4).Value & "    " & Cells(i + 5, 4).Value

                        Else '~~~~~>RANGE1.VALUE = RANGE2.VALUE BELOW

                                Cells(i + 4, 52).Value = 5
                                Range(Cells(i, 40), Cells(i, 50)).Value = Range(Cells(i + 4, 53), Cells(i + 4, 63)).Value
                                Range(Cells(i + 1, 40), Cells(i + 1, 50)).Value = Range(Cells(i + 4, 64), Cells(i + 4, 74)).Value
                                Range(Cells(i + 2, 40), Cells(i + 2, 50)).Value = Range(Cells(i + 4, 75), Cells(i + 4, 85)).Value
                                Range(Cells(i + 3, 40), Cells(i + 3, 50)).Value = Range(Cells(i + 4, 86), Cells(i + 4, 96)).Value

                                i = i + 4

                             End If

1 个答案:

答案 0 :(得分:2)

在Visual Basic中的语句

stackdf <- do.call(rbind, list.name)
stackdf
#    loc sub.loc    V3
# 1    A       1 -0.56
# 2    A       2 -0.23
# 3    A       3  1.56
# 4    B       1  0.07
# 5    B       2  0.13
# 6    B       3  1.72
# 7    A       1  0.46
# 8    A       2 -1.27
# 9    A       3 -0.69
# 10   B       1 -0.45
# 11   B       2  1.22
# 12   B       3  0.36
# 13   A       1  0.40
# 14   A       2  0.11
# 15   A       3 -0.56
# 16   B       1  1.79
# 17   B       2  0.50
# 18   B       3 -1.97

dfs <- by(stackdf, stackdf[c("loc", "sub.loc")], FUN=function(df) {      
  data.frame(loc = df$loc[1],
             sub.loc = df$sub.loc[1],
             mean = mean(df$V3, na.rm=TRUE),
             sd = sd(df$V3, na.rm=TRUE))
})

finaldf <- do.call(rbind, dfs)
finaldf
#   loc sub.loc        mean        sd
# 1   A       1  0.10000000 0.5723635
# 2   B       1  0.47000000 1.1723481
# 3   A       2 -0.46333333 0.7189808
# 4   B       2  0.61666667 0.5542863
# 5   A       3  0.10333333 1.2631838
# 6   B       3  0.03666667 1.8661279

修改a = b ,以便为其赋予a的值。它不会将b更改为b的值。

根据您对AN:AX中数据的评论,您似乎打算使用:

a