Code: Select all
Sub Foundcopy()
Dim nRange As Range, aCell As Range, bCell As Range
Dim SearchString As String, FoundAt As String
Dim ws As Worksheet
Dim ExitLoop As Boolean
Dim r As Range, rString As String
Dim lastRow As Long
On Error GoTo Err
Set ws = Worksheets("sheet1")
lastRow = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
Set nRange = ws.Range("A2:F" & lastRow)
Name = Application.InputBox("ãÊè¢éÍÁÙÅ·Õèµéͧ¡Òäé¹ËÒ", "*")
Set aCell = nRange.Find(What:=Name, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not aCell Is Nothing Then
Set bCell = aCell
FoundAt = aCell.Address
Do While ExitLoop = False
Set aCell = nRange.FindNext(After:=aCell)
If Not aCell Is Nothing Then
If aCell.Address = bCell.Address Then Exit Do
FoundAt = FoundAt & ", " & aCell.Address
Else
ExitLoop = True
End If
Loop
Else
MsgBox SearchString & "äÁ辺¢éÍÁÙÅ"
End If
MsgBox "µÓá˹觷Õ辺: " & FoundAt
For Each r In Range(FoundAt)
rString = rString & "," & r.Resize(1, 6).Address
Next r
Range(Mid(rString, 2)).Copy
Range("H1").PasteSpecial xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
Exit Sub
Err:
MsgBox Err.Description
End Sub
ปัญหาคือ ถ้าผมค้นหาข้อความหรือตัวเลขได้แล้วให้ คัดลอกมาทั้งแถว ยกตัวอย่าง
ค้นหา a1 มีในช่อง a2 , d5 , b8 แล้ว ให้คัดลอก a2:f2 , a5:f5 , a8:f8 มาวางไว้ที่ h1 ตามลำดับที่แสดงไว้ใน
ไฟล์แนบครับ
จะปรับอย่างไรครับ
คัดลอกมาได้แต่ไม่ได้ตามที่ต้องการครับ
Foundcopy 2.xlsm
You do not have the required permissions to view the files attached to this post.