EXCEL TOOLS
Excel Add-ins ที่พัฒนาโดยคุณสันติพงศ์ ณสุย (MVP Excel 2010-2020) ด้วยภาษา C# เพื่อแก้ไขปัญหาไฟล์ใหญ่ คำนวณนาน ทำงานช้า จัดการข้อมูลต่าง ๆ ที่ทำงานประจำวันได้อย่างสะดวกรวดเร็ว สนใจคลิกไปดูได้ที่นี่ครับ => Excel Tools
Excel Add-ins ที่พัฒนาโดยคุณสันติพงศ์ ณสุย (MVP Excel 2010-2020) ด้วยภาษา C# เพื่อแก้ไขปัญหาไฟล์ใหญ่ คำนวณนาน ทำงานช้า จัดการข้อมูลต่าง ๆ ที่ทำงานประจำวันได้อย่างสะดวกรวดเร็ว สนใจคลิกไปดูได้ที่นี่ครับ => Excel Tools
[code]
และปิดด้วย [/code]
ตัวอย่างเช่น [code]dim r as range[/code]
เพื่อให้แตกต่างจากข้อความทั่วไป สะดวกในการอ่านและทดสอบ (คลิกเพื่อดูตัวอย่าง)Code: Select all
Sub insert_col()
'
' insert_col Macro
'
'
Columns("K:L").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("O:P").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("S:T").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
End Sub
Code: Select all
Dim rAll As Range
Dim i As Integer
Dim k As Integer
Dim a As Variant
With Sheets("data_orginal")
Set rAll = .Range("h1:xfd1").SpecialCells(xlCellTypeConstants)
a = Split(rAll.Address, ",")
k = UBound(a)
For i = k To 0 Step -1
.Range(a(i)).Resize(1, 2).EntireColumn.Insert
Next i
End With
Code: Select all
Dim rAll As Range
Dim i As Integer
Dim k As Integer
With Sheets("Sheet1")
Set rAll = .Range("h1:xfd1").SpecialCells(xlCellTypeConstants)
For i = rAll.Count To 1 Step -1
Debug.Print rAll(i).Address
rAll(i).Resize(1, 2).EntireColumn.Insert
Next i
End With
Code: Select all
Sub add_2_col()
Dim rAll As Range
Dim i As Integer
Dim k As Integer
Dim a As Variant
With Sheets(2)
Set rAll = .Range("h1:xfd1").SpecialCells(xlCellTypeConstants)
For i = rAll.Count To 1 Step -1
a = Split(rAll.Address, ",")
rAll(i).Resize(1, 2).EntireColumn.Insert
Next i
End With
End Sub
Code: Select all
Dim rAll As Range
Dim i As Integer
Dim k As Integer
With Sheets("Sheet2")
Set rAll = .Range("h1", .Range("xfd1").End(xlToLeft))
i = rAll.Count
For k = i To 1 Step -1
If rAll(k).Value <> "" Then
rAll(k).Resize(1, 2).EntireColumn.Insert
End If
Next k
End With