dbaruzzini
New Member
- Joined
- Nov 24, 2015
- Messages
- 13
Hello, and thank you in advance for any guidance you are willing to offer.
Basic Info: Excel 2013; SharePoint 2013; Windows Enterprise
I have a lot of things going on with this code since the material I wish to copy is located in a drive, mapped to a SharePoint library. The range I wish to copy is dynamic based on how many rows of data there are in each workbook. The code I have displayed below is actually a sub procedure I have called to another.
The code works beautifully except for one part... The last two non-adjacent cells (.cells(rw, 39) & .cells(rw, 44)) do not copy correctly. I get an #N/A error for both. I am open to ideas. Ideally, I would love to include the objFile.Path also into the Union function but it will not accept it due to the fact that it's not a range.
Here is the code:
Basic Info: Excel 2013; SharePoint 2013; Windows Enterprise
I have a lot of things going on with this code since the material I wish to copy is located in a drive, mapped to a SharePoint library. The range I wish to copy is dynamic based on how many rows of data there are in each workbook. The code I have displayed below is actually a sub procedure I have called to another.
The code works beautifully except for one part... The last two non-adjacent cells (.cells(rw, 39) & .cells(rw, 44)) do not copy correctly. I get an #N/A error for both. I am open to ideas. Ideally, I would love to include the objFile.Path also into the Union function but it will not accept it due to the fact that it's not a range.
Here is the code:
Code:
Public Sub GetAllFilesFolders(Objfolder As Object, SharepointAddress As String)
Dim objFile As Object
Dim wkbk As Workbook
Dim startrow As Long
Dim endrow As Long
Dim TWB As ThisWorkbook: Set TWB = ThisWorkbook
Dim rw As Long
Dim Row As Long
Dim TWRG As Range
Application.ScreenUpdating = False
Set TWRG = TWB.Sheets(1).[A1]
For Each objFile In Objfolder.Files
Set wkbk = Workbooks.Open(objFile.Path, False, True, IgnoreReadOnlyRecommended:=True)
DoEvents
With wkbk.Sheets(1)
startrow = 8
endrow = .Cells(.Rows.Count, 1).End(xlUp).Row
For rw = startrow To endrow
TWRG.Offset(1, 0) = objFile.Path
TWRG.Offset(1, 1).Resize(1, 10) = _
Union(.Cells(rw, 1), .Cells(rw, 2), .Cells(rw, 3), _
.Cells(rw, 4), .Cells(rw, 5), .Cells(rw, 6), _
.Cells(rw, 7), .Cells(rw, 8), .Cells(rw, 39), .Cells(rw, 44)).Value
Set TWRG = TWRG.Offset(1, 0)
DoEvents
Next rw
End With
wkbk.Close False
DoEvents
Next
Application.ScreenUpdating = True
End Sub