vba For循环粘贴中间有空行的行

时间:2016-12-20 15:56:10

标签: vba for-loop copy-paste

我试图循环遍历每100行的行,然后将其粘贴到活动工作簿中。由于某种原因,我无法弄清楚,副本似乎工作正常,但粘贴,应该粘贴到范围(E2:V2),它粘贴到E3:V3,然后每次它通过for循环它跳过另一行。因此,不是粘贴到E2:V2,而是E3:V3,然后是E5:V5。

# what it should look like 
ID = c(rep("A",3),rep("A1",2) , rep("B",3), rep("B1",2))
DateTime = c("2014-09-25 08:39:45", "2014-09-25 08:39:48", "2014-09-25 08:40:44", "2014-09-25 09:04:00","2014-09-25 09:04:10", "2014-09-25 08:33:32", "2014-09-25 08:34:41", "2014-09-25 08:35:24", "2014-09-25 09:04:00", "2014-09-25 09:04:09")
speed = c(1:10)
timeDiff<-c(NA,3,56,1396,10,NA,69,43,1716,9)
newdf = data.frame(ID,DateTime,speed,timeDiff, stringsAsFactors = FALSE)
newdf$DateTime<-as.POSIXct(df$DateTime, tz = "UTC")
newdf

2 个答案:

答案 0 :(得分:0)

您正尝试将buffer数组放入Awb.Sheets("Sheet1")中的范围,因此您最后不需要Rows(AwbRownum)

只需改变你的行:

Awb.Sheets("Sheet1").Range("E" & AwbRownum, "V" & AwbRownum).Rows(AwbRownum).Value = buffer

为:

Awb.Sheets("Sheet1").Range("E" & AwbRownum, "V" & AwbRownum).Value = buffer

答案 1 :(得分:0)

当你写:

Awb.Sheets("Sheet1").Range("E" & AwbRownum, "V" & AwbRownum).Rows(AwbRownum).Value = buffer

.Rows(AwbRownum)是由Awb.Sheets("Sheet1").Range("E" & AwbRownum, "V" & AwbRownum)定义的范围的偏移量。