vba macro swap two column values ?

muhmath2002

New Member
Joined
Dec 16, 2019
Messages
26
Office Version
  1. 2007
Platform
  1. Windows
hi all
i need vba code with button browse file excel then swap multiple two column values
columns A B
columns C D
columns E F
then save changes in the same file
best regards
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
try this;
VBA Code:
Sub test()
For i = 1 To 5 Step 2
    lasta = Cells(Rows.Count, i).End(xlUp).Row
    ar = Range(Cells(1, i), Cells(lasta, i))
    Range(Cells(1, i), Cells(lasta, i)) = ""
    lastb = Cells(Rows.Count, i + 1).End(xlUp).Row
    br = Range(Cells(1, i + 1), Cells(lastb, i + 1))
    Range(Cells(1, i + 1), Cells(lastb, i + 1)) = ""
    Range(Cells(1, i), Cells(lastb, i)) = br
    Range(Cells(1, i + 1), Cells(lasta, i + 1)) = ar
Next i
ActiveWorkbook.Save
End Sub
 
Upvote 0
try this;
VBA Code:
Sub test()
For i = 1 To 5 Step 2
    lasta = Cells(Rows.Count, i).End(xlUp).Row
    ar = Range(Cells(1, i), Cells(lasta, i))
    Range(Cells(1, i), Cells(lasta, i)) = ""
    lastb = Cells(Rows.Count, i + 1).End(xlUp).Row
    br = Range(Cells(1, i + 1), Cells(lastb, i + 1))
    Range(Cells(1, i + 1), Cells(lastb, i + 1)) = ""
    Range(Cells(1, i), Cells(lastb, i)) = br
    Range(Cells(1, i + 1), Cells(lasta, i + 1)) = ar
Next i
ActiveWorkbook.Save
End Sub
mr offthelip
big thanks for advance vba code
work perfectly
 
Upvote 0
Hi, according to Excel basics a VBA demonstration for starters :​
VBA Code:
Sub Demo1()
    With ActiveSheet.UsedRange
        .Value = Application.Index(.Columns("A:F"), Evaluate("ROW(1:" & .Rows.Count & ")"), [{2,1,4,3,6,5}])
        .Parent.Parent.Save
    End With
End Sub
 
Upvote 0
Hi, according to Excel basics a VBA demonstration for starters :​
VBA Code:
Sub Demo1()
    With ActiveSheet.UsedRange
        .Value = Application.Index(.Columns("A:F"), Evaluate("ROW(1:" & .Rows.Count & ")"), [{2,1,4,3,6,5}])
        .Parent.Parent.Save
    End With
End Sub
brother Mrac L
thanks for nice vba code it work perfectly
best wishes
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,871
Members
449,054
Latest member
juliecooper255

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