【发布时间】:2014-05-02 08:20:24
【问题描述】:
我已经编写了这个宏,它应该遍历一个范围,如果该范围包含一个数字,则将偏移单元格复制到 csv 或另一张表中。目前,当我执行它运行的代码时,它不会中断但是我的文本文件中没有输出,也没有任何错误消息。
不知道怎么回事?任何指针?请帮忙谢谢。
Dim rng As Range, cell As Range
Dim ofset As String
Dim filepath As String
Set rng = Range("F1:F100")
For Each cell In rng
If IsError(cell) Then
'MsgBox "cell " & cell.Address & " contains error"
ElseIf cell.Value > 0 Then
ofset = cell.Offset(, -2).Resize(, 2).Select 'gives you B1:C1
' copy this range to text file
filepath = Application.DefaultFilePath & "\authors.csv"
Open filepath For Output As #2
Write #2, cell.Value & ofset
Close #2
End If
Next cell
MsgBox "The values have been copied"
【问题讨论】:
-
这段代码末尾有
Next语句吗? -
你在这里期望什么结果:
ofset = cell.Offset(, -2).Resize(, 2).Select考虑到Dim ofset As String? -
我认为 id 将 cell.offset 值放入变量中。我认为更容易操纵?是的,最后有一个声明@Portland Runner