• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 
hiteshgoldeneyeCommented:
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
 
hiteshgoldeneyeCommented:
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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

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