Hi Team,
I am trying to develop a macro to cut the second part of the report which is present in the existing sheet and then by doing vlook up to insert those values in the existing report.
Explanation:
I have a report which is split into two parts. The first part starts from A1 and then second part starts from row named New. The second part of the report consists of 10 columns and the first part of the reports consists of 30 columns. I have to insert 10 columns in the first part of the report i.e. have to insert columns from second part into first set of report after Column U and before Column V.
One column is unique between both set of reports (Column named - Position Identifier) using which vlookup has to be done and values inserted.
Sample report attached and below is the coding that i am using.
The newly inserted columns must appear in the original report after C30 and before U1. After inserting columns and doing vlookup --> convert to values the second part of the report must be deleted.
I am getting error msg while using this code, but could not identify where to rectify it
Can anyone please help .
I am trying to develop a macro to cut the second part of the report which is present in the existing sheet and then by doing vlook up to insert those values in the existing report.
Explanation:
I have a report which is split into two parts. The first part starts from A1 and then second part starts from row named New. The second part of the report consists of 10 columns and the first part of the reports consists of 30 columns. I have to insert 10 columns in the first part of the report i.e. have to insert columns from second part into first set of report after Column U and before Column V.
One column is unique between both set of reports (Column named - Position Identifier) using which vlookup has to be done and values inserted.
Sample report attached and below is the coding that i am using.
The newly inserted columns must appear in the original report after C30 and before U1. After inserting columns and doing vlookup --> convert to values the second part of the report must be deleted.
I am getting error msg while using this code, but could not identify where to rectify it
Can anyone please help .
Code:
Sub sixtyfiveMoveReport()
Dim pg2 As Range
Dim part2Report As Range
Dim destRange As Range
Dim part2Row As Long
Dim myCol As Long
Dim impPath As String
impPath = RetrieveFileName()
If impPath = "" Then Exit Sub 'User cancelled
Workbooks.Open (impPath)
Set pg2 = Range("A:A").Find("New")
part2Row = pg2.Row
Set pg2 = pg2.Offset(2, 1)
Set part2Report = Range(pg2, pg2.End(xlToRight).End(xlDown))
myCol = 22
Application.ScreenUpdating = False
Cells(1, myCol).Resize(1, part2Report.Columns.Count).EntireColumn.Insert
With part2Report
.Rows(1).Cut
ActiveSheet.Paste Destination:=Cells(10, myCol)
Set destRange = Range(Cells(9, myCol), Cells(part2Row - 1, Cells(10, myCol).Offset(0, .Columns.Count - 1).Column))
destRange.Formula = _
"=VLOOKUP($V25," & .Offset(0, -1).Resize(, .Columns.Count + 1).Address(True) & ",COLUMN(B$2),FALSE)"
destRange.Value = destRange.Value
.Clear
End With
Range(part2Row & ":65536").EntireRow.Delete
Application.ScreenUpdating = True
End Sub
Private Function RetrieveFileName()
'obtained from:
Dim sFileName As String
ChDir ThisWorkbook.Path
"sFileName"
sFileName = Application.GetOpenFilename(FileFilter:=myFilter, Title:="Multi Worksheet Import", MultiSelect:=False)
If sFileName = "False" Then Exit Function
RetrieveFileName = sFileName
End Function