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 searchtest()
Dim lastrow As Long, x As Long
lastrow = Sheets("data2").Cells(Rows.Count, 1).End(xlUp).Row
For x = 2 To lastrow
If Sheets("data2").Cells(x, 1).Value = Sheets("Result").Range("a2").Value And Sheets("data2").Cells(x, 2).Value = Sheets("Result").Range("b2").Value Then
Sheets("Result").Range("c2").Value = Sheets("data2").Cells(x, 3).Value
Exit Sub
End If
Next x
End Sub
Code: Select all
Sub A_Unique_B()
Dim X
Dim objDict As Object
Dim lngRow As Long
Set objDict = CreateObject("Scripting.Dictionary")
X = Application.Transpose(Range([a1], Cells(Rows.Count, "A").End(xlUp)))
For lngRow = 1 To UBound(X, 1)
objDict(X(lngRow)) = 1
Next
Range("F2:F" & objDict.Count) = Application.Transpose(objDict.Keys)
End Sub
ตอบอันนี้ก่อนครับปรับโค้ดตามนี้ครับkannaree wrote:ขอบคุณค่ะ
Code: Select all
Sub searchtest() Dim lastrow As Long, x As Long lastrow = Sheets("data2").Cells(Rows.Count, 1).End(xlUp).Row For x = 2 To lastrow If Sheets("data2").Cells(x, 1).Value = Sheets("Result").Range("a2").Value And Sheets("data2").Cells(x, 2).Value = Sheets("Result").Range("b2").Value Then Sheets("Result").Range("c2").Value = Sheets("data2").Cells(x, 3).Value Exit Sub End If Next x End Sub
Code: Select all
Sub FilterAndCopy()
Dim wstSource As Worksheet, _
wstOutput As Worksheet
Dim rngMyData As Range, _
helperRng As Range
Set wstSource = Worksheets("Data2")
Set wstOutput = Worksheets("Result")
Application.ScreenUpdating = False
With wstSource
Set rngMyData = .Range("A2:C" & .Range("A" & .Rows.Count).End(xlUp).Row)
End With
Set helperRng = rngMyData.Offset(, rngMyData.Columns.Count + 1).Resize(, 1)
With helperRng
.FormulaR1C1 = "=if(countif(C1,RC1)>1,"""",1)"
.Value = .Value
.SpecialCells(xlCellTypeBlanks).EntireRow.Copy Destination:=wstOutput.Cells(1, 1)
.ClearContents
End With
Application.ScreenUpdating = True
End Sub
ปรับตามนี้ครับkannaree wrote:ขอถามอีกคำถามหนึงได้ไหมค่ะ
พอดีพึ่งจะเริ่มหัดเขียน vba
มีข้อมูลอยู่ใน Sheet "data3"
ใช้สูตร Unique ในการ Find หาข้อมูลในเซล A
ให้แสดงผลลัพทธ์ ตัดค่าที่ซ้ำกันออก ผลลัพธ์ในเซลล์ F ตามรูป
1112.png
>> อยากให้ข้อมูลไปแสดงใน Sheet3 cell C8 จะต้องแก้ Code ในส่วนไหน อย่างไรบ้างคะ ****Code: Select all
Sub A_Unique_B() Dim X Dim objDict As Object Dim lngRow As Long Set objDict = CreateObject("Scripting.Dictionary") X = Application.Transpose(Range([a1], Cells(Rows.Count, "A").End(xlUp))) For lngRow = 1 To UBound(X, 1) objDict(X(lngRow)) = 1 Next Range("F2:F" & objDict.Count) = Application.Transpose(objDict.Keys) End Sub
ขอบคุณค่ะ
Code: Select all
Sub A_Unique_B()
Dim X
Dim objDict As Object
Dim lngRow As Long
Set objDict = CreateObject("Scripting.Dictionary")
X = Application.Transpose(Range([a1], Cells(Rows.Count, "A").End(xlUp)))
For lngRow = 1 To UBound(X, 1)
objDict(X(lngRow)) = 1
Next
Sheets("Sheet3").Range("C1:C" & objDict.Count).Offset(7, 0) = Application.Transpose(objDict.Keys)
End Sub
Code: Select all
Sub summaryReport()
Dim X
Dim objDict As Object
Dim lngRow As Long
Set objDict = CreateObject("Scripting.Dictionary")
Sheet1.Select
X = Application.Transpose(Range([a2], Cells(Rows.Count, "A").End(xlUp)))
For lngRow = 1 To UBound(X, 1)
objDict(X(lngRow)) = 1
Next
Sheet3.Select
Range("C7:C" & objDict.Count) = Application.Transpose(objDict.Keys)
End Sub
Code: Select all
Application.Transpose(Range([a2], Cells(Rows.Count, "A").End(xlUp)))
Code: Select all
Sub summaryReport()
Dim X
Dim objDict As Object
Dim lngRow As Long
Set objDict = CreateObject("Scripting.Dictionary")
X = Application.Transpose(Range([a2], Cells(Rows.Count, "A").End(xlUp)))
For lngRow = 1 To UBound(X, 1)
objDict(X(lngRow)) = 1
Next
Sheet3.Range("C1:C" & objDict.Count).Offset(6, 0) = Application.Transpose(objDict.Keys)
End Sub