snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Private Sub Test1_Click()
Dim CCenter As String
Dim rCode, rAll, r, r1 As Range
With Sheets("Existing")
Set rAll = .Range("a:a").SpecialCells(xlCellTypeConstants)
CCenter = .Range("A1")
End With
For Each r In rAll
With Sheets("data")
Set rCode = .Range("e:e").SpecialCells(xlCellTypeConstants)
For Each r1 In rCode
If r1.Value = CCenter Then
r.Offset(3, 1) = r1.Offset(, -4)
End If
Next r1
End With
Next r
End Sub
You do not have the required permissions to view the files attached to this post.
Private Sub Test1_Click()
Dim CCenter As String
Dim rCode, rAll, r, r1 As Range
With Sheets("Existing")
Set rAll = .Range("a:a").SpecialCells(xlCellTypeConstants)
CCenter = .Range("A1")
End With
For Each r In rAll
With Sheets("data")
Set rCode = .Range("e:e").SpecialCells(xlCellTypeConstants)
For Each r1 In rCode
If r1.Value = CCenter Then
r.Offset(3, 1) = r1.Offset(, -4)
End If
Next r1
End With
Next r
End Sub
Dim CCenter As String
Dim rCode, rAll, r, r1 As Range
With Sheets("Existing")
Set rAll = .Range("a:a").SpecialCells(xlCellTypeConstants)
CCenter = .Range("A1")
End With
For Each r In rAll
With Sheets("data")
Set rCode = .Range("e:e").SpecialCells(xlCellTypeConstants)
For Each r1 In rCode
If r1.Value = CCenter Then
r1.Offset(, -4).Copy
Sheets("Existing").Range("b" & Rows.Count) _
.End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Application.CutCopyMode = False
'r.Offset(3, 1) = r1.Offset(, -4)
End If
Next r1
End With
Next r