snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
Dim rall As Range
Dim r As Range
With Sheets("EDIT")
Set rall = .Range("t3", .Range("t" & .Rows.Count).End(xlUp))
For Each r In rall
If r.Value <> "" Then
.Range(r.Value).Value = r.Offset(0, -3).Value
End If
Next r
End With
ตัวอย่าง Code เมื่อนำข้อมูลจาก Form กลับไปวางในชีต Data
Dim rall As Range
Dim r As Range
Dim numRow As Long
With Sheets("EDIT")
Set rall = .Range("t3", .Range("t" & .Rows.Count).End(xlUp))
For Each r In rall
If r.Value <> "" Then
r.Offset(0, 1).Value = .Range(r.Value).Value
End If
Next r
rall.Offset(0, 1).Copy
If Application.CountIf(Sheets("data").Range("a:a"), .Range("c3").Value) > 0 Then
numRow = Application.Match(.Range("c3").Value, Sheets("Data").Range("a:a"), 0) - 1
Sheets("Data").Range("a" & numRow).PasteSpecial Paste:=xlPasteValues, Transpose:=True
Else
Sheets("Data").Range("a" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues, _
Transpose:=True
End If
End With
Dim rall As Range
Dim r As Range
With Sheets("EDIT")
Set rall = .Range("t3", .Range("t" & .Rows.Count).End(xlUp))
For Each r In rall
If r.Value <> "" Then
.Range(r.Value).Value = r.Offset(0, -3).Value
End If
Next r
End With
ตัวอย่าง Code เมื่อนำข้อมูลจาก Form กลับไปวางในชีต Data
Dim rall As Range
Dim r As Range
Dim numRow As Long
With Sheets("EDIT")
Set rall = .Range("t3", .Range("t" & .Rows.Count).End(xlUp))
For Each r In rall
If r.Value <> "" Then
r.Offset(0, 1).Value = .Range(r.Value).Value
End If
Next r
rall.Offset(0, 1).Copy
If Application.CountIf(Sheets("data").Range("a:a"), .Range("c3").Value) > 0 Then
numRow = Application.Match(.Range("c3").Value, Sheets("Data").Range("a:a"), 0) - 1
Sheets("Data").Range("a" & numRow).PasteSpecial Paste:=xlPasteValues, Transpose:=True
Else
Sheets("Data").Range("a" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues, _
Transpose:=True
End If
End With