I'm at a complete loss here. My Coding allows for me to return a Value when Offset (0,1) is chosen and when Offset (1,1) is chosen. However, for what I am trying to use this for, I'm trying to look farther away - one example of this is Offset (0,3), but when I attempt this - it gives me a Blank Value.
I have attempted Offset.Value, Offset.Value2, and Offset.Text with no luck. If someone could please look over my code and offer a suggestion or give me another work around - I would appreciate it.
I have scaled it down as small as possible to make it easier to decipher and I all I'm looking to do is Post Data from a Worksheet("Detailed") to a Worksheet("Reports").
Thanks in advance, Ronnie.
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
This will be my example worksheet where I am pulling data from:
A B C D E F G
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
When I have Offset(0,1) it correctly pulls data and posts it accurately:
A
1
2
3
4
5 27
6 31
7
8
9
10 14
11 18
However, when I change Offset(0, 3) - Zero Data is posted. I created the MsgBox (DetailedCel.Offset(0, 3).Value2) to see what the value is, but returns nothing. I do not understand why.
I'm unsure why,but this works fine on my office 2010 and I only experienced it on my office 2007 suite. Sorry for the confusion and thank you to everyone who looked at the code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.