شاید برای شما پیش آمده باشد که در فایل
اکسل خود دادههایی را در یک ستون طولانی درج کرده باشید مانند شکل زیر :
1
2
3
4
A
B
C
D
!
@
#
$
و بخواهید این ستون طولانی را به چند ستون کوتاه تبدیل کنید :
1 A !
2 B @
3 C #
4 D $
برای این کار میتوانید از ماکروها استفاده کنید برای فعال کردن پنجره ماکرو :
Alt+F11 -> Insert -> Module
سپس کد زیر را در کادر مربوطه وارد کنید :
Sub ToManyColumns()
Dim firstCellRow As Long
firstCellRow = 1 change this if you dont want to start at A1
Dim firstCellColumn As Long
firstCellColumn = 1 change this if you dont want to start at A1
Application.ScreenUpdating = False
ActiveSheet.Cells(firstCellRow, firstCellColumn).Activate
Dim column As Long
column = firstCellColumn
Dim startIndex As Long
Dim endIndex As Long
Dim lastRow As Long
lastRow = firstCellRow
Do While True
find the range to copy
startIndex = ActiveCell.row
Do While ActiveCell.Value <> ""
endIndex = ActiveCell.row
ActiveCell.Offset(1).Activate
Loop
lastRow = ActiveCell.row
Range(Cells(startIndex, firstCellColumn), Cells(endIndex, firstCellColumn)).Select
Selection.Copy
Cells(firstCellRow, column).Select
Selection.PasteSpecial Paste:=xlPasteValues
get back to last rowIndex
Cells(lastRow, firstCellColumn).Activate
ActiveCell.Offset(1).Activate
If ActiveCell.Value = "" Then Exit Do
column = column + 1
Loop
cleanUp -------------------------------------------
Dim deleteFrom As Long
Dim deleteTo As Long
deleteTo = ActiveCell.row
ActiveSheet.Cells(firstCellRow, firstCellColumn).Activate
Do While ActiveCell.Value <> ""
ActiveCell.Offset(1).Activate
Loop
deleteFrom = ActiveCell.row
Range(Cells(deleteFrom, firstCellColumn), Cells(deleteTo, firstCellColumn)).Select
Selection.ClearContents
ActiveSheet.Cells(firstCellRow, firstCellColumn).Activate
cleanUp -------------------------------------------
Application.ScreenUpdating = True
End Sub
حال باید این مایکرو را اجرا کنید.در قسمت بالا گزینه فلش کوچک یا کلید F5 را بزنید تا ماکرو اجرا شود و ستون طولانی اکسل شما به چند ستون کوتاه تبدیل شود.