I have code that is intended to loop through a range and add text in the adjacent field if a file is found. Everything works excpet that the text does not get put in the field. Any help identifying where the issues are would be helpful. Here is the code:
Sub test2()
Dim ii As Long
Dim Rng As String
Rng = ActiveCell.Value
Dim fln As String
Dim Rng1 As String
Dim ERng As String
Dim CRng As Integer
Dim SCell As Range
fln = ActiveCell.Offset(, ColumnOffset:=-1).Value
Rng1 = ActiveCell.Address
'MsgBox Right(Rng1, Len(Rng1) - 3)
Selection.End(xlDown).Select
ERng = ActiveCell.Address
'MsgBox Right(ERng, Len(ERng) - 3)
CRng = Right(ERng, Len(ERng) - 3) - Right(Rng1, Len(Rng1) - 3)
'MsgBox CRng
'Selection.End(xlUp).Select
'ActiveCell.Offset(RowOffset:=1).Activate
Application.Goto Reference:=Worksheets("Qry_Cust_Notification").Range(Rng1)
'Set ActiveSheet.ActiveCell = SCell
If CRng > 0 Then
For cc = 1 To CRng
With Application.FileSearch
.NewSearch
.Filename = Rng & "_20070101.pdf"
.SearchSubFolders = True
.LookIn = "N:\Annual Price Increase_2007\PDF Price List\WebPriceList\"
MsgBox "Just Before IF to Check for files"
If .Execute() > 0 Then
MsgBox .Execute
For ii = 1 To .FoundFiles.Count
MsgBox "In the Found Files Count"
ActiveCell.Offset(, ColumnOffset:=1).Activate
ActiveCell.Value = .FoundFiles(ii)
ActiveCell.Offset(RowOffset:=1, ColumnOffset:=-1).Activate
Next ii
Else
MsgBox "No File Found"
ActiveCell.Offset(RowOffset:=1).Activate
End If
End With
Next cc
Else
MsgBox "No Records Left"
End If
End Sub
Sub test2()
Dim ii As Long
Dim Rng As String
Rng = ActiveCell.Value
Dim fln As String
Dim Rng1 As String
Dim ERng As String
Dim CRng As Integer
Dim SCell As Range
fln = ActiveCell.Offset(, ColumnOffset:=-1).Value
Rng1 = ActiveCell.Address
'MsgBox Right(Rng1, Len(Rng1) - 3)
Selection.End(xlDown).Select
ERng = ActiveCell.Address
'MsgBox Right(ERng, Len(ERng) - 3)
CRng = Right(ERng, Len(ERng) - 3) - Right(Rng1, Len(Rng1) - 3)
'MsgBox CRng
'Selection.End(xlUp).Select
'ActiveCell.Offset(RowOffset:=1).Activate
Application.Goto Reference:=Worksheets("Qry_Cust_Notification").Range(Rng1)
'Set ActiveSheet.ActiveCell = SCell
If CRng > 0 Then
For cc = 1 To CRng
With Application.FileSearch
.NewSearch
.Filename = Rng & "_20070101.pdf"
.SearchSubFolders = True
.LookIn = "N:\Annual Price Increase_2007\PDF Price List\WebPriceList\"
MsgBox "Just Before IF to Check for files"
If .Execute() > 0 Then
MsgBox .Execute
For ii = 1 To .FoundFiles.Count
MsgBox "In the Found Files Count"
ActiveCell.Offset(, ColumnOffset:=1).Activate
ActiveCell.Value = .FoundFiles(ii)
ActiveCell.Offset(RowOffset:=1, ColumnOffset:=-1).Activate
Next ii
Else
MsgBox "No File Found"
ActiveCell.Offset(RowOffset:=1).Activate
End If
End With
Next cc
Else
MsgBox "No Records Left"
End If
End Sub