Hi All,
I am so close to finishing this project but have stumbled into a problem. I have tred to adap tthe code below so that rather than pasting data into a new workbook it pastes into my work active workbook onto sheet one from cell b4 to iv4 and repeats as many times as necessary.
I am being hit with this error when the code hits:
"The information cannot be pasted because the Copy areaand the paste area are not the same size or shape. Try one of the following:
- Click a single cell and then paste
- Select a rectangle thats the same size and shape, and then paste."
Any help or advice would make my day!
Thanks
Paul
I am so close to finishing this project but have stumbled into a problem. I have tred to adap tthe code below so that rather than pasting data into a new workbook it pastes into my work active workbook onto sheet one from cell b4 to iv4 and repeats as many times as necessary.
I am being hit with this error when the code hits:
Code:
sourceRange.Copy
With destrange
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
Transpose = True
"The information cannot be pasted because the Copy areaand the paste area are not the same size or shape. Try one of the following:
- Click a single cell and then paste
- Select a rectangle thats the same size and shape, and then paste."
Code:
#If VBA7 Then
Declare PtrSafe Function SetCurrentDirectoryA Lib _
"kernel32" (ByVal lpPathName As String) As Long
#Else
Declare Function SetCurrentDirectoryA Lib _
"kernel32" (ByVal lpPathName As String) As Long
#End If
Sub ChDirNet(szPath As String)
SetCurrentDirectoryA szPath
End Sub
Sub Basic_Example_2()
Dim MyPath As String
Dim SourceRcount As Long, Fnum As Long
Dim mybook As Workbook, BaseWks As Worksheet
Dim sourceRange As Range, destrange As Range
Dim rnum As Long, CalcMode As Long
Dim SaveDriveDir As String
Dim FName As Variant
'Change ScreenUpdating, Calculation and EnableEvents
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
.EnableEvents = False
End With
SaveDriveDir = CurDir
ChDirNet "G:\BID\SWOT\Adult Service Redesign\ABC Pilot\Data\"
FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xl*), *.xl*", _
MultiSelect:=True)
If IsArray(FName) Then
'Set destination as
Set BaseWks = ActiveWorkbook.Worksheets(1)
rnum = 1
'Loop through all files in the array(myFiles)
For Fnum = LBound(FName) To UBound(FName)
Set mybook = Nothing
On Error Resume Next
Set mybook = Workbooks.Open(FName(Fnum))
On Error GoTo 0
If Not mybook Is Nothing Then
On Error Resume Next
With mybook.Worksheets(3)
Set sourceRange = .Range("b3:iv3")
End With
If Err.Number > 0 Then
Err.Clear
Set sourceRange = Nothing
Else
'if SourceRange use all columns then skip this file
If sourceRange.Columns.Count >= BaseWks.Columns.Count Then
Set sourceRange = Nothing
End If
End If
On Error GoTo 0
If Not sourceRange Is Nothing Then
SourceRcount = sourceRange.Rows.Count
If rnum + SourceRcount >= BaseWks.Rows.Count Then
MsgBox "Sorry there are not enough rows in the sheet"
BaseWks.Columns.AutoFit
mybook.Close savechanges:=False
GoTo ExitTheSub
Else
'Copy the file name in column A
With sourceRange
BaseWks.Cells(rnum, "A"). _
Resize(.Rows.Count).Value = FName(Fnum)
End With
'Set the destrange
Set destrange = BaseWks.Range("B" & rnum)
'we copy the values from the sourceRange to the destrange
sourceRange.Copy
With destrange
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
Transpose = True
End With
rnum = rnum + SourceRcount
End If
End If
mybook.Close savechanges:=False
End If
Next Fnum
BaseWks.Columns.AutoFit
End If
Dim Last_Row As Long
'Finds last used cell in column b
Range("B65536").End(xlUp).Select
ExitTheSub:
'Restore ScreenUpdating, Calculation and EnableEvents
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = CalcMode
End With
ChDirNet SaveDriveDir
End Sub
Any help or advice would make my day!
Thanks
Paul