Help With Complicated Code Please

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,786
Office Version
  1. 365
Platform
  1. 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
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
If this code is complicating things maybe someone could come up with another code that will do the same thing please.
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,633
Members
452,933
Latest member
patv

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top