Excel VBA .Offset(0,3).Value不返回值

我在这里完全损失。 我的编码允许我select偏移量(0,1)和偏移量(1,1)时返回一个值。 然而,对于我正在尝试使用这种方法,我试图远一些 – 这是Offset(0,3)的一个例子,但是当我尝试这样做时,它给了我一个空白值。

我已经尝试Offset.Value,Offset.Value2和Offset.Text没有运气。 如果有人可以请看看我的代码,并提出一个build议或给我另一个工作 – 我将不胜感激。

我把它缩小到尽可能小,以便更容易解密,我所要做的就是将数据从工作表(“详细”)发布到工作表(“报告”)。

在此先感谢,罗尼。

Sub TEST() Dim DetailedSrchRng As Range, DetailedCel As Range Set DetailedSrchRng = Range("C1:C15") Dim DMArray(1 To 3), GMArray(1 To 2, 1 To 2), GMRow(1 To 8), X As Integer, Y As Integer DMArray(1) = "DistributionMailing1" DMArray(2) = "DistributionMailing2" DMArray(3) = "0" GMArray(1, 1) = "GeneralMailing1" GMArray(1, 2) = "GeneralMailing2" GMArray(2, 1) = "GeneralMailing3" GMArray(2, 2) = "0" X = 3 Do Until DMArray(X) <> "0" X = X - 1 Loop A = X X = 1 For X = 1 To 3 If X > A Then Exit For End If GMRow(1) = 5 GMRow(2) = 10 For Y = 1 To 2 For Each DetailedCel In DetailedSrchRng If DetailedCel.Value = GMArray(X, Y) Then 'The Code Listed Directly Below Was A Workaround I Tried, It Didn't Work Either 'Worksheets("Reports").Range("A" & GMRow(Y)) = DetailedCel.Offset(0, 3).Value2 ActiveWorkbook.Worksheets("Reports").Cells(GMRow(Y), 1).Value = DetailedCel.Offset(0, 3).Value2 MsgBox (DetailedCel.Offset(0, 3).Value2) GMRow(Y) = GMRow(Y) + 1 End If Next DetailedCel Next Y Next X End Sub 

这将是我的示例工作表,我从中提取数据:

  ABCDEFG 1 GeneralMailing1 1 2 3 4 2 GeneralMailing1 5 6 7 8 3 9 10 11 12 13 4 GeneralMailing2 14 15 16 17 5 GeneralMailing2 18 19 20 21 6 22 23 24 25 26 7 GeneralMailing3 27 28 29 30 8 GeneralMailing3 31 32 33 34 9 35 36 37 38 39 10 40 41 42 43 44 11 GeneralMailing4 45 46 47 48 12 GeneralMailing4 49 50 51 52 13 53 54 55 56 57 14 58 59 60 61 62 

当我有偏移量(0,1)时,它会正确地拉取数据并准确地发布:

  A 1 2 3 4 5 27 6 31 7 8 9 10 14 11 18 

但是,当我更改偏移(0,3) – 零数据张贴。 我创build了MsgBox(DetailedCel.Offset(0,3).Value2)来查看这个值是什么,但是什么也没有返回。 我不懂为什么。

我不确定为什么,但这在我的办公室2010工作正常,我只在我的办公室2007年套件经历。 对不起,我感到困惑,并感谢所有查看代码的人。