Sorry the question is not so specified. I've tried to use Set to help me filling a quelity control table, but the error 10o4 show up. It seems correct for me and so I don't know how to correct it. So please take a look of it, and leave a comment if you've got some idea. Thank you!
Private Sub FillTarget(ByVal TargetSheet As String, ByVal DepositSheet As String, _
ByVal TargetRow As Integer, ByVal TargetColumn As String, _
ByVal DepositRow As Integer, ByVal DepositColumn As Integer)
Dim i, j, k As Integer
Dim OpenedFile As String
Dim myObject As String
Dim MarkRow As Integer
MarkRow = 1
Dim myData As String
Dim EndSearch As Boolean
Dim TargetCell As Range
Dim TargetTag As Range
Dim TargetType As Range
Dim TargetZone As Range
Dim TargetTest As Range
Dim DepositTag As Range
Dim DepositZone As Range
Dim DepositResult As Range
For i = 3 To TargetRow
With Worksheets(TargetSheet)
myObject = .Cells(i, 15).Text + "_" + Worksheets(TargetSheet).Cells(i, 17).Text
Set TargetCell = .Cells(i, TargetColumn) <==== Here comes the error
Set TargetTag = .Cells(i, 15)
Set TargetType = .Cells(i, 17)
Set TargetZone = .Cells(i, 18)
Set TargetTest = .Cells(i, 20)
End With
For j = MarkRow To DepositRow
With Worksheets(DepositSheet)
Set DepositTag = .Cells(j, 1)
Set DepositZone = .Cells(j, 2)
End With
If InStr(DepositTag.Text, myObject) <> 0 Then
OpenedFile = OpenedFile & DepositTag.Text & "|"
If InStr(DepositZone.Text, TargetZone.Text + ":") <> 0 _
Or InStr(TargetZone.Text, "/") <> 0 Then
For k = 2 To DepositColumn
With Worksheets(DepositSheet)
Set DepositResult = .Cells(j, k)
End With
If InStr(DepositResult.Text, TargetTest.Text) <> 0 Then
MarkRow = j
myData = DepositResult.Text
'Split_monData
'Derniere_Colonne
TargetCell.Value = myData
EndSearch = True
Exit For
End If
Next k
End If
End If
If EndSearch Then Exit For
Next j
EndSearch = False
Next i
End Sub
Dim range1 As Rangenew lineDim range2 As Range, they all can be written asDim range1 As Range, range2 As Range. Important to note that you must always include theAs Range(or whatever the object is), or that particular variable will be auto-declared as a VariantOption Explicitabove yourSubso you'll always have to declare your variables. Also, be careful when you declareDim i, j, k As Integeronlykis declared as integer, i and j will be asVariantyou need to writeDim i As Integer, j As Integer, k As IntegerOption Exolicit, could you please explain a little bit? I don't know why and how to use it.Option Explicitin the first line of your module. This way if you are using a variable that you forgot to declare when you run the macro it won't work. link