Forum

Notifications
Clear all

how to move and automatically sort data?

7 Posts
2 Users
0 Reactions
58 Views
(@stanislavash)
Posts: 4
Active Member
Topic starter
 

Hello, 

I would like to ask someone to help me with this:

I have a table that is filled regularly and the data is not sorted. I need all this data to be automatically copied to another file, because there we add an additional column and I linked both tables  but I want the data to be sorted automatically by submission date  in the second table.

I attach an example file with two sheets, not linked.

Thank you

P.S. Excel 2016 on PC

 
Posted : 22/07/2020 2:34 am
(@purfleet)
Posts: 412
Reputable Member
 

Somthing like this?

Sub CopySort()

Worksheets("Table 1").Range("a1").CurrentRegion.Copy Worksheets("Table 2").Range("a1")

Worksheets("Table 2").Range("a:a").Columns.Insert xlToLeft

With Worksheets("Table 2").Range("a1")
.Value = "Comment"
.Interior.Color = vbBlue
.Font.Color = vbWhite
End With

Worksheets("Table 2").Range("a1").CurrentRegion.Sort KEY1:=Worksheets("Table 2").Range("C:C"), ORDER1:=xlAscending, Header:=xlYes

Worksheets("Table 2").Activate

End Sub

 
Posted : 22/07/2020 9:27 am
(@stanislavash)
Posts: 4
Active Member
Topic starter
 

Hi, yes, exactly, thank you very much.

But I won't be able to write it myself. Also, the example I gave is between two sheets, but I need this between two workbooks. 

If I attach the exact tables that I use (columns) in different workbooks, would you help me again?

Do the two workbooks need to be open in order to work?

 
Posted : 22/07/2020 11:57 am
(@purfleet)
Posts: 412
Reputable Member
 

The concept is simular with 2 workbooks and we can get VBA to open the workbooks if we know where they are located.

I will update the code later and repost

 
Posted : 24/07/2020 1:03 am
(@stanislavash)
Posts: 4
Active Member
Topic starter
 

Hi Purfleet, a kind reminder 🙂

It would make my life much easier and I apologize if I am being pushy.

Thank you

 
Posted : 20/08/2020 2:41 am
(@purfleet)
Posts: 412
Reputable Member
 

Sorry, completly forgot

Tried to make it as flexible as possible, might be overkill

you need to put the destination Drive,Workbook name, sheet name and range and starting worksheet name and range on the input page - this will not check is the file or range actually exists so you need to make sure the path & file name etc are 100% correct.

at the end of the code i have set the destination worksheet to autosave and the starting wort to save and close - take these out if you dont want this to happen

'Saves Destination worksheet
Workbooks(DestWb).Save

'Close orginal worksheet
Workbooks(StartWb).Close True

There is lots more that can be done to make this macro better - such as check the file are there and that the input fields are populated, but i will leave that to you to improve as you see fit.

 
Posted : 21/08/2020 1:14 pm
(@stanislavash)
Posts: 4
Active Member
Topic starter
 

Thank you.

I will do my best.

 
Posted : 22/08/2020 7:29 am
Share: