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 Combinetabs()
Sheets.Add
ActiveSheet.Name = "New Sheet"
Set Dsheet = ActiveSheet
For Each ws In Sheets
If ws.Name <> "New Sheet" Then
lr = ws.Cells(Rows.Count, "A").End(xlUp).Row
lr2 = Dsheet.Cells(Rows.Count, "A").End(xlUp).Row
If lr2 = 1 Then lr2 = 0
ws.Rows("1:" & lr).Copy Dsheet.Range("A" & lr2 + 1)
End If
Next ws
End Sub
Sub Transform()
Set sh = ThisWorkbook.Sheets("New Sheet")
lr = sh.Cells(Rows.Count, "B").End(xlUp).Row
usdRate = sh.Range("AD2").Value
For i = 2 To lr
With sh
If .Cells(i, "F").Value = "KHR" Then
.Range("D" & i).Value = .Range("D" & i).Value / usdRate
.Range("E" & i).Value = .Range("E" & i).Value / usdRate
.Range("N" & i).Value = .Range("N" & i).Value / usdRate
.Range("P" & i).Value = .Range("P" & i).Value / usdRate
.Range("Q" & i).Value = .Range("Q" & i).Value / usdRate
.Range("R" & i).Value = .Range("R" & i).Value / usdRate
.Range("T" & i).Value = .Range("T" & i).Value / usdRate
.Range("U" & i).Value = .Range("U" & i).Value / usdRate
.Range("W" & i).Value = .Range("W" & i).Value / usdRate
.Range("X" & i).Value = .Range("X" & i).Value / usdRate
.Range("Y" & i).Value = .Range("Y" & i).Value / usdRate
.Range("Z" & i).Value = .Range("Z" & i).Value / usdRate
End If
End With
Next
End Sub
Code: Select all
Sub combinetabs()
Sheets.Add before:=Sheets(1)
ActiveSheet.Name = "New Sheet"
Set Dsheet = ActiveSheet
For Each ws In Sheets
If ws.Name <> "New Sheet" Then
lr = ws.Cells(Rows.Count, "A").End(xlUp).Row
lr2 = Dsheet.Cells(Rows.Count, "A").End(xlUp).Row
If lr2 = 1 Then lr2 = 0
ws.Rows("1:" & lr).Copy Dsheet.Range("A" & lr2 + 1)
End If
Next ws
With Worksheets("New Sheet")
lr = .Cells(Rows.Count, "B").End(xlUp).Row
usdRate = .Range("AD2").Value
If IsEmpty(usdrange) Then
MsgBox "Please enter USD rate in cell AD2.", vbCritical
Exit Sub
End If
For i = 2 To lr
If .Cells(i, "F").Value = "KHR" Then
.Range("D" & i).Value = .Range("D" & i).Value / usdRate
.Range("E" & i).Value = .Range("E" & i).Value / usdRate
.Range("N" & i).Value = .Range("N" & i).Value / usdRate
.Range("P" & i).Value = .Range("P" & i).Value / usdRate
.Range("Q" & i).Value = .Range("Q" & i).Value / usdRate
.Range("R" & i).Value = .Range("R" & i).Value / usdRate
.Range("T" & i).Value = .Range("T" & i).Value / usdRate
.Range("U" & i).Value = .Range("U" & i).Value / usdRate
.Range("W" & i).Value = .Range("W" & i).Value / usdRate
.Range("X" & i).Value = .Range("X" & i).Value / usdRate
.Range("Y" & i).Value = .Range("Y" & i).Value / usdRate
.Range("Z" & i).Value = .Range("Z" & i).Value / usdRate
End If
Next
End With
End Sub
Code: Select all
Sub combinetab()
Sheets.Add before:=Sheets(1)
ActiveSheet.Name = "New Sheet"
Set Dsheet = ActiveSheet
For Each ws In Sheets
If ws.Name <> "New Sheet" Then
lr = ws.Cells(Rows.Count, "A").End(xlUp).Row
lr2 = Dsheet.Cells(Rows.Count, "A").End(xlUp).Row
If lr2 = 1 Then lr2 = 0
ws.Rows("1:" & lr).Copy Dsheet.Range("A" & lr2 + 1)
End If
Next ws
usdrate = Sheet1.Range("AD1").Value
If IsEmpty(usdrate) Then
MsgBox "Please enter USD rate ", vbCritical
Exit Sub
End If
With Worksheets("New Sheet")
lr = .Cells(Rows.Count, "B").End(xlUp).Row
idn = ""
For i = 2 To lr
If IsNumeric(VBA.Left(.Cells(i, "a"), 4)) And IsEmpty(.Cells(i, "b").Value) Then
idn = .Cells(i, "a").Value
End If
If .Cells(i, "F").Value = "KHR" Then
.Range("D" & i).Value = .Range("D" & i).Value / usdrate
.Range("E" & i).Value = .Range("E" & i).Value / usdrate
.Range("N" & i).Value = .Range("N" & i).Value / usdrate
.Range("P" & i).Value = .Range("P" & i).Value / usdrate
.Range("Q" & i).Value = .Range("Q" & i).Value / usdrate
.Range("R" & i).Value = .Range("R" & i).Value / usdrate
.Range("T" & i).Value = .Range("T" & i).Value / usdrate
.Range("U" & i).Value = .Range("U" & i).Value / usdrate
.Range("W" & i).Value = .Range("W" & i).Value / usdrate
.Range("X" & i).Value = .Range("X" & i).Value / usdrate
.Range("Y" & i).Value = .Range("Y" & i).Value / usdrate
.Range("Z" & i).Value = .Range("Z" & i).Value / usdrate
End If
If Not IsEmpty(.Range("ab" & i).Value) Then
.Range("ac" & i).Value = idn
End If
Next
End With
End Sub