การทำฟอร์มกรอกข้อมูล แบบที่ 1 data entry forms

Option Explicit
Sub clear()
Range(“C2:C20”).ClearContents
Range(“C2”).Select
End Sub
Sub Save()
Dim c As Integer
Dim m As String
Range(“C2:C20”).Copy
c = findcolumn(Range(“A2”).Value)
Cells(23, c).Select
Selection.PasteSpecial xlPasteValues
Range(“C2:C20”).ClearContents
Range(“C2”).Select
End SubPrivate Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Target.Range.Address = “$C$1” Then
Call clear
End If
If Target.Range.Address = “$D$1” Then
Call Save
End If
End Sub

Function findcolumn(m) As Integer
Dim i As Integer
For i = 3 To 14
If Cells(22, i).Value = m Then
Exit For
End If
Next i
findcolumn = i
End Function

download