• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

Can we sort colum according to our requirement

Hi,

I have a excel sheet which has many colums
EX;
Srl No   Name   Age   Address   City   State   Country
Many time i need to take reports in different ways so is there a way to shift these colums according to my requirement.Any inbuilt way or a macro to change according to my input.
Say a macro asks 1st colum .I say 3 and next 4 and then 1 so on.

This would run until all colums get over.

regards
Sharath
0
bsharath
Asked:
bsharath
  • 5
  • 4
1 Solution
 
bsharathAuthor Commented:
This will sort the internal content.What i want is shift colums according to my requirement
Say I want A to be next to G
0
 
bsharathAuthor Commented:
Any help.../
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
bsharathAuthor Commented:
I want a way to shift colums not sort.

Like a macro asks me Sort ( i enter A,G,E) and the colums shift there paths.
0
 
bsharathAuthor Commented:
Any help....
0
 
Hitesh ManglaniCommented:
Sub shiftcolumn()
Dim str1 As Variant, s1row As Long
Dim s1col As Integer
s1col = 255
str1 = Split(InputBox("Columns nos"), ",") 'Enter column nos separated by , e.g (1,3,)


            For k = 1 To UBound(str1)
                  Sheet1.Columns(k).Copy Destination:=Sheet1.Columns(s1col)
                  Sheet1.Columns(Val(str1(k - 1))).Copy Destination:=Sheet1.Columns(k)
                  Sheet1.Columns(s1col).Copy Destination:=Sheet1.Columns(Val(str1(k - 1)))
           
             Next



End Sub
0
 
bsharathAuthor Commented:
1. Can the data in sheet 1 be copied to sheet 2 and do the changes
2. Can't we use colum Name instead of no's?
3. Can we only specify 1,3,5 instead of 1,3,5,
0
 
Hitesh ManglaniCommented:
ok here you go
Sub shiftcolumn()
Dim str1 As Variant, s1row As Long
Dim s2col As Integer
s2col = 1
str1 = Split(InputBox("Columns Letters"), ",") 'Enter column nos separated by , e.g (A,B)
            For k = 1 To UBound(str1) + 1
                  Sheet1.Columns(str1(k - 1)).Copy Destination:=Sheet2.Columns(s2col)
                  s2col = s2col + 1
             Next
End Sub

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now