Dazzawm
Well-known Member
- Joined
- Jan 24, 2011
- Messages
- 3,786
- Office Version
- 365
- Platform
- Windows
I was given the code below that will copy all the rows I highlight then put them in all the files within a folder. It puts them at the the bottom of the destination files. Is it possible for the code to look at column C on the source file and the destination files and insert the rows alphabetically rather than adding them to the bottom? Thanks.
Code:
Sub CopyRowsFromSourceIntoAllCats()
' This will copy selected rows from the source wookbook into all the
' files within the folder remember all worksheets must be named sheet1
'Application.ScreenUpdating = False
wb = ActiveWorkbook.Name
If ActiveCell = "" Then GoTo endd
'Get Range to be copied
x = ActiveWindow.RangeSelection.Address
srow = "": erow = "": di = 0: Dim PJ(): z = 0
For a = 1 To Len(x)
If Mid$(x, a, 1) = ":" Then di = 1
If IsNumeric(Mid$(x, a, 1)) = True Then
If di = 0 Then
srow = srow + Mid$(x, a, 1)
Else
erow = erow + Mid$(x, a, 1)
End If
End If
Next a
If erow = "" Then erow = srow
FType = "C:\Documents and Settings\MANAGER\Desktop\Dazzas\*.xlsm"
Fname = Dir(FType)
Do Until Fname = ""
If Fname = wb Then GoTo Next1
z = z + 1
ReDim Preserve PJ(1 To z)
PJ(z) = Fname
Next1:
Fname = Dir
Loop
For a = 1 To z
Workbooks.Open "C:\Documents and Settings\MANAGER\Desktop\Dazzas\" + PJ(a)
ActiveWorkbook.Sheets("Sheet1").Activate
r = ActiveWorkbook.Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row + 1
Workbooks(wb).Sheets("Sheet1").Rows(srow & ":" & erow).Copy
ActiveWorkbook.Sheets("Sheet1").Cells(r, 1).Select
ActiveSheet.Paste
ActiveWorkbook.Close savechanges:=True
Next a
endd:
'Application.ScreenUpdating = True
End Sub