2017-07-03 339 views
0

首先,我将所有需要的数据存储到数组中,然后将其与列进行比较;如果它匹配,那么我会采取值的偏移量,并将其放入另一列。将单元格与VBA中的数组进行比较

但是在数组中,我遇到“无效限定符”错误。我究竟做错了什么?

Sub database_updator() 

Dim dataa As Range, dataCel1 As Range, dataj As Range, datacel2 As Range, datazc As Range, datacel3 As Range, SrchRngaa As Range, cel As Range 

Dim data As String, datatext As String, PDS_NAME As String, Database_data As String 
Dim n As Integer, xx As Integer, z As Integer 
Set dataa = Range("a16:a100") 
Set datazc = Range("zc17:zc50") 
Set SrchRngaa = Range("a16:a100") 
Dim arr(1 To 85) As String 
x = 16 
For n = 1 To 85  'storing data into array 
    arr(n) = Range("yx" & x).Value 
    x = x + 1 
Next n 


' loop thorugh cells in column 
For Each dataCel1 In datazc 
    For n = 1 To 85 
     If arr(n) = dataCel1.Value Then 
      datatext = "true" 
     Exit For 
     End If 
    Next n 

' check if current value in column has a match in another column 
    If datatext = "true" Then 
     PDS_NAME = arr(n).Value ' ERROR OCCURS HERE 
    Database_data = dataCel1.Offset(0, 2).Value 
      For Each cel In SrchRngaa 
       If PDS_NAME = "" Then 

       Exit For 
       ElseIf cel.Value = PDS_NAME Then 

         cel.Offset(0, 2).Value = Database_data 

       Exit For 

       End If 
      Next cel 
    End If 




Next dataCel1 

End Sub 
+6

你不需要'ARR(N)的 “.value的” .Value' – MiguelH

+0

有没有'数组的.Value'财产。试试'= arr(n)' – Ambie

回答

0
PDS_NAME = arr(n).Value 

this should be changed to: 

PDS_NAME = arr(n) 
相关问题