Page 1 of 1

Excel กับการหาค่าทีไม่ซ้ำ

Posted: Tue Dec 11, 2012 7:15 pm
by godman
สวัสดีครับ
พอดีผมกำลังต้องการหา code vba ที่หารายการที่ไม่ซ้ำก้น และลิสต์รายการออกมาวางไว้ใน คอลัมพใดคอลัมพหนึ่งภายในชี้ตเดียวกัน แต่โค้ดที่ผมได้มา ใช้ได้ดีมาก เพียงแต่ผมไม่อยากให้มันขึ้น msg box ที่ต้องให้ระบุเซลล์ที่จะให้นำข้อมูลไปวาง ความต้องการของผมคือ อยากให้มันวางลงใน c1 หรือ D1 หรืออะไรก็ได้ให้เราเปลี่ยนเอาใน code แทน จึงขอให้ท่านผู้รู้ช่วยแนะนำว่าต้องแก้ไขโค้ดนี้ตรงส่วนใหนครับ

Code: Select all

Sub UniqueList()
Dim rListPaste As Range
Dim iReply As Integer

On Error Resume Next

Set rListPaste = Application.InputBox _
(Prompt:="Please select the destination cell", Type:=8)

    If rListPaste Is Nothing Then
       iReply = MsgBox("No range nominated," _
          & " terminate", vbYesNo + vbQuestion)
      If iReply = vbYes Then Exit Sub
    End If

'May need to specify [NameofSheet].Range, e.g, Sheet1.Range
   Range("A1", Range("A65536").End(xlUp)).AdvancedFilter _
   Action:=xlFilterCopy, CopyToRange:=rListPaste.Cells(1, 1), Unique:=True
End Sub

Re: Excel กับการหาค่าทีไม่ซ้ำ

Posted: Tue Dec 11, 2012 8:36 pm
by snasui
:D ลองปรับ Code เป็นตามด้านล่างครับ

Code: Select all

Sub UniqueList()
    On Error Resume Next
    'May need to specify [NameofSheet].Range, e.g, Sheet1.Range
    Range("A1", Range("A65536").End(xlUp)).AdvancedFilter _
    Action:=xlFilterCopy, CopyToRange:=Sheets("Sheet1").Cells(1, "C"), Unique:=True
End Sub

Re: Excel กับการหาค่าทีไม่ซ้ำ

Posted: Tue Dec 11, 2012 8:54 pm
by godman
ทำได้แล้วครับ สุดยอดเลย ขอบคุณมากครับ ตรงความต้องการ