Arranging data in ascending order

akassociates

New Member
Joined
Oct 13, 2017
Messages
1
Hi,
I am new to VBA and not so good to code writing. Can you please help me on below -

I am having 3 work sheets (Worksheet names - A-P, I-P, Q-Z) with tables of data in each of them. I am having another worksheet called as - "Entry".
I want to copy the data entered in "Entry" sheet to either of these 3 sheets.
Conditions -
1 - Copy the data from B9:K9 of "Entry" sheet
2 - Define the worksheet to which row should be pasted (Either of - A-P, I-P, Q-Z), depending on first alphabet in cell B9 of "Entry" sheet
3 - Go to the bottom of the table and paste the copied row
4 - Arrange the data in the table as per ascending order with expanded range
5 - Clear the "Entry" row after data is pasted to its destination

Thank you.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi, welcome to the board!

Here is some code you can try, note there is some overlap in your description which I have assumed to be a typo.

should be pasted (Either of - A-P, I-P, Q-Z)

Code:
Sub ArrangeData()

Dim destWS As Worksheet
    
Select Case UCase(Left(Sheets("Entry").Range("B9").Value, 1))
    Case "A" To "H": Set destWS = Sheets("A-H")
    Case "I" To "P": Set destWS = Sheets("I-P")
    Case Else: Set destWS = Sheets("Q-Z")
End Select

With Sheets("Entry").Range("B9:K9")
    .Copy Destination:=destWS.Range("B" & destWS.Rows.Count).End(xlUp).Offset(1)
    .ClearContents
End With

destWS.Range("B1").CurrentRegion.Sort destWS.Range("B1"), xlAscending

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,839
Messages
6,121,891
Members
449,058
Latest member
Guy Boot

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