i have a piece of code that copies a row from one excel to another. The problem is that columns E to G an N to O have a reference to another excel and when it copies it copies the formula not the cell value resulting in repeating the formula to the target column in descending order. I have tried with hide/ unhide but it doesn't do much difference. The target column D it will result in D1= 1.xslm/sheet1/formula(n1) ; D2= 2.xslm/sheet1/formula(n2) ... - that are the reference from the source sheet column D. In the source the values are ok, in the target the formula is just wrong and it shouldn't have n1, n2 ... . If the source row is 122 in target it should be D1= 1.xslm/sheet1/formula(n122) , D2= 2.xslm/sheet1/formula(n122)
Sub copy1()
Dim c As Range
Dim j As Integer
Dim Source As Worksheet
Dim Target As Worksheet
Dim Sour As String
Dim Tar As String
Dim path As String
Dim AutoSR As Workbook
Dim asrSheet As Worksheet
Set AutoSR = ActiveWorkbook
Set Target = AutoSR.ActiveSheet
path = "c:\first.xlsm"
Tar = "Sheet1"
Set Source = Workbooks.Open(path).Sheets(Tar)
Source.Unprotect Password:="XXX"
Application.DisplayAlerts = False
Columns("E:G").EntireColumn.Hidden = False
Columns("N:O").EntireColumn.Hidden = False
Source.Range("N:O").EntireColumn.Hidden = True
For Each c In Source.Range("a1:a" & Cells.SpecialCells(xlCellTypeLastCell).Row)
If c = lNum Then
Source.Rows(c.Row).Copy Target.Rows(1)
End If
Next c
Source.Range("E:G").EntireColumn.Hidden = True
Source.Range("N:O").EntireColumn.Hidden = True
Source.Protect Password:="XXX"
Source.Activate
ActiveWorkbook.Close SaveChanges:=True
Set Source = Nothing
End Sub