PDA

View Full Version : VBA Code: ascending order of the columns



murthysri272
02-23-2016, 09:33 AM
Hi,
I have a spreadsheet which is having Column A to B. I want to sort the column A as alphabetical order (So cells which are having same values should come together), so all columns should adjust with that accordingly.

can we able to achieve this scenario in VBA code? If yes, please provide me the sample code.


Sample data for the scenario is as below:

Column A Column B
KALA $58
KAZO $123.7
KA55 $23.5
CBHY $14.0
AMJ0 $99
CBHY $73.0
AMJ0 $34
KAZO $13.0
KA55 $28.5
CT00 $12
KALA $76
KL76 $34

Regards,
Sri

mikerickson
02-23-2016, 10:42 AM
Record a macro:

Press Record Macro
Select columns A and B (and all others that you want to be moved with the sort)
Sort on column A
Press Stop Recording.

murthysri272
02-23-2016, 01:09 PM
.

murthysri272
02-23-2016, 01:10 PM
Okay Mike,
I got it.
Thanks for your suggestion.

After sort My data (INPUT) is as below, is there anyway I can get my result (OUTPUT) using VBA Macros? If it is feasible please help me with sample code.

Input:

Column A Column B

AMJ0 $34
AMJ0 $99

CBHY $14.0
CBHY $73.0

CT00 $12

KALA $58
KALA $76

KAZO $123.7
KAZO $13.0

KA55 $28.5
KA55 $23.5

KL76 $34

Output:

AMJ0 $133

CBHY $87.0

CT00 $12

KALA $134

KAZO $136.7

KA55 $52.0

KL76 $34


Regards,
Sri

mikerickson
02-23-2016, 03:02 PM
The formula =SUMIF(A:A, "AMJ0", B:B) will give you the sum for AMJ0

You can use AdvancedFilter to generate a list of unique names and then put a formula in the next column.

OHHH... by the way. Everyone should know that there is a cross post at
http://www.ozgrid.com/forum/showthread.php?t=198782