• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Sorting Data in other Workbook

macro_learning

New Member
Hi All,

Please refer to the vba code in attached excel name "testing". I want it to first open other workbook "fbb" and then sort data in this workbook.

Can anyone please let me know the problem in this macro.

And secondly, kindly share me the code for copying folders and/or files from one location to other.


Regards,
macro_learning.
 

Attachments

  • fbb.xlsx
    8.6 KB · Views: 4
  • testing.xlsm
    14.4 KB · Views: 3
I want it to sort data in excel "fbb".

Basically, I want to first open another workbook say "xyz" and want to sort data in this workbook "xyz".


is it something that we can not manipulate data in workbook opened by macro written in another excel?

Regards,
macro_learning
 
Change code to this

Code:
Sub edit()

    Dim strPath As String
    Dim strName As String
    Dim wbNew As Workbook

    strPath = Range("a1")
    strName = Range("a2")
   
    Application.ScreenUpdating = False
    Set wbNew = Workbooks.Open(strPath & "\" & strName)
   
   
    With wbNew.Worksheets(1).Sort
        .SortFields.Clear
        .SortFields.Add Key:=Range("a1"), Order:=xlAscending
        .SetRange Range("A1:B5")
        .Header = xlYes
        .MatchCase = False
        .SortMethod = xlPinYin
        .Apply
    End With
    Application.ScreenUpdating = True
End Sub
 
Thank you so much...it is working perfect.

I want to sort the data in the attached "fbb" workbook.

by two field (or column) , "A1" & "B1".

Regards,
macro_learning.
 

Attachments

  • fbb.xlsx
    8.8 KB · Views: 1
  • testing.xlsm
    15 KB · Views: 1
In a2 of your testing workbook, need to give full name, including extension. Change a2 to be:
fbb.xlsx
 
Back
Top