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
Private Sub AddBotton_Click()
If SecOptM = True Then
Dim LinesToInsert As Variant
Dim rTarget As Range
With Sheets("MAIN")
'Set rTarget = Range("a" & .Rows.Count).End(xlUp).Offset(-6, 0)
Set r = ActiveCell
Sheets("Main").Select: Range("b9").Select ' SHEET TARGET
Do Until UCase(ActiveCell.Value) = "ANNUALLY"
ActiveCell.Offset(1, 0).Select ' find the range named "ID"
Loop
ActiveCell.Offset(0, 0).Select
intR = ActiveCell.Row
'LinesToInsert = InputBox("How many Rows to insert? ") ' Ask for how many rows needs
LinesToInsert = RowNTextBox
For Each c In r
If c.Value <> "" Then
Do Until ActiveCell.Value = ""
If UCase(ActiveCell.Value) = UCase(c.Value) And _
c.Value <> "" Then
If Val(LinesToInsert) <= 50 Then
On Error Resume Next
r.EntireRow.Resize(Int(LinesToInsert)).Insert
End If
Else
ActiveCell.Offset(1, 0).Select
End If
Loop
End If
Cells(intR, 2).Select
Next
End With
End If
End Sub
Code: Select all
For Each c In r
If c.Value <> "" Then
Do Until ActiveCell.Value = ""
If UCase(ActiveCell.Value) = UCase(c.Value) And _
c.Value <> "" Then
If Val(LinesToInsert) <= 50 Then
On Error Resume Next
r.EntireRow.Resize(Int(LinesToInsert)).Insert
End If
Else
ActiveCell.Offset(0, 0).Select
End If
Loop
End If
Cells(intR, 2).Select
Code: Select all
Private Sub AddBotton_Click()
Dim x$, y&
If (SecOptM = True Or SecOptA = True) _
And RowNTextBox <> "" Then
With Sheets("MAIN")
x = IIf(SecOptM, "Annually", "Total")
y = Application.Match(x, .Range("b:b"), 0)
.Range("b" & y).Resize(RowNTextBox).EntireRow.Insert
End With
End If
End Sub
Dim x$, y&
มีค่าเท่ากับ Dim s As String, y as Long
x = IIf(SecOptM, "Annually", "Total")
เป็นการกำหนดค่าให้กับตัวแปร x โดยมีเงื่อนไขว่า หาก SecOptM ถูกเลือก ให้ x มีค่าเป็น "Annualy" หาก SecOptM ไม่ถูกเลือก ให้ x มีค่าเป็น "Total"y = Application.Match(x, .Range("b:b"), 0)
เป็นการกำหนดค่าให้กับตัวแปร y โดยให้ไปค้นว่าค่า x อยู่ในคอลัมน์ b ในลำดับที่เท่าไร ก็ให้ y มีค่าเท่านั้นRange("b" & y).Resize(RowNTextBox).EntireRow.Insert
เป็นการแทรกบรรทัดใน คอลัมน์ b บรรทัดที่ y จำนวน RowNTextBox บรรทัด