snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Sub CopyData()
Dim i As Integer
Dim lastrow As Integer
lastrow = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrow
If Cells(i, 3).Value <> 0 Then 'To find cells which have value in column C
Cells(i, 1).Copy
Cells(i, 3).Copy
Worksheets("Sheet2").Range("A2").Paste
End If
Next i
Worksheets("Sheet2").Select
Worksheets("Sheet2").Name = "Cavity"
End Sub
ขอคำชี้แนะด้วยค่ะ
You do not have the required permissions to view the files attached to this post.
Sub CopyData()
Dim i As Long
Dim lastrow As Long, lastrow2 As Long
lastrow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
lastrow2 = Sheets(2).Cells(Rows.Count, 1).End(xlUp).Row + 1
For i = 2 To lastrow
If Cells(i, 3).Value <> 0 Then 'To find cells which have value in column C
Sheets("cavity").Cells(lastrow2, 1).Value = _
Sheets(1).Cells(i, 1).Value
Sheets("cavity").Cells(lastrow2, 2).Value = _
Sheets(1).Cells(i, 3).Value
lastrow2 = lastrow2 + 1
End If
Next i
Sheets(2).Select
Sheets(2).Name = "Cavity"
End Sub