Hi Team,
please help, My task is to open each workbooks from a range, copy workbooks range and paste in master file,
But Challenge I am facing is that firstworkbooks data will be pasted correctly. but second workbooks
Data should be pasted in specified range of Master workbook.and row should be adjusted.
I think it needs to check workbooks name and jump to that correct range
Thanks in advance for precious time and help.
Regards,
Mallesh
please help, My task is to open each workbooks from a range, copy workbooks range and paste in master file,
But Challenge I am facing is that firstworkbooks data will be pasted correctly. but second workbooks
Data should be pasted in specified range of Master workbook.and row should be adjusted.
I think it needs to check workbooks name and jump to that correct range
Thanks in advance for precious time and help.
Code:
Option Explicit
Sub Test()
Dim i As Integer
Dim wbk As Workbook
Dim mwbk As Workbook
Dim inputsheet As Worksheet
Dim outputsheet As Worksheet
Dim path As String
Dim lr As Long
Set mwbk = ThisWorkbook
Set inputsheet = mwbk.Worksheets("Input")
Set outputsheet = wbk.Worksheets("MasterFile")
path = "E:\"
For i = 6 To 9
On Error Resume Next
Set wbk = Workbooks.Open(inputsheet.Range("b6").Value, ReadOnly:=True)
On Error GoTo 0
'if wbk.Name = Team1 then do this activity
'if wbk.Name = Team2 then jump2 Team2 steps
Set Datasheet = wbk.Worksheets("Sheet1") 'My data sheet to copy the data
If wbk Is Nothing Then Exit Sub 'Plz assist is this line correct
If Not wbk Is Nothing Then ' if wbk found continue
lr = Datasheet.Range("a65555").End(xlUp).Row
If lr < 2 Then GoTo closeworkbook
'if lr is 15 row then i have insert extra row ****** Challenges*******
'and format should also maintain as it it
Datasheet.Range("a1").currenregion.Copy
outputsheet.Range("b4").PasteSpecial xlPasteAll
End If
End If
GoTo closeworkbook:
wbk.Close False
Next i
End Sub
Regards,
Mallesh
Last edited by a moderator: