0
InputBoxから値を挿入するためにコードを取得するのに問題があります。特に問題のある行は、次のとおりです。Excel VBA:xlDownとOffsetを使用してセルに値を挿入する
Set p = nPoints.End(xlDown).Offset(1, 0)
p.Value = nPointVal
このがスプレッドシートの最後の行、右への最初の利用可能なセルを見つけて、格納された値nPointVal
を挿入されて何をすべきか。しかし、そうするのではなく、単に何も挿入しません。どんな助力も大変ありがとうございます。私の完全なコードは以下の通りです。
Sub takeTwo()
On Error Resume Next
Dim fNameString As Variant
Dim lNameString As Variant
Dim sEmailString As Variant
Dim nPointVal As Integer
Dim sEventName As String
Dim n As Integer, r As Long, c As Range, d As Range, e As Range, p As Range, sE As Range
Dim fName As Range, lName As Range, sEmail As Range, nPoints As Range
Dim lEvent As Integer
Set fName = ActiveSheet.Range("FirstName")
Set lName = ActiveSheet.Range("LastName")
Set sEmail = ActiveSheet.Range("eMailAddr")
fNameString = Split(Application.InputBox("First Names in comma delimited format.", Type:=2), ",")
lNameString = Split(Application.InputBox("Last Names in comma delimited format.", Type:=2), ",")
sEmailString = Split(Application.InputBox("Email Addresses in comma delimited format.", Type:=2), ",")
nPointVal = InputBox("Please enter a point value for this event")
sEventName = InputBox("Please enter the name of the event.")
lEvent = NextEmptyColumn(Range("A1"))
Set sE = Range("A1").Offset(0, lEvent)
sE.Value = sEventName
' sEventPos = sE.Offset(0, lEvent)
If fNameString <> False And lNameString <> False Then
For i = LBound(fNameString) To UBound(fNameString)
fNameString(i) = Trim(fNameString(i)) ' Trim off leading and trailing whitespace.
lNameString(i) = Trim(lNameString(i)) ' Trim off leading and trailing whitespace.
Set c = fName.Find(fNameString(i), LookIn:=xlValues, LookAt:=xlWhole)
Set d = lName.Find(lNameString(i), LookIn:=xlValues, LookAt:=xlWhole)
If c And d Is Nothing Then
Set c = fName.End(xlDown).Offset(1, 0)
c.Value = fNameString(i)
Set d = lName.End(xlDown).Offset(1, 0)
d.Value = lNameString(i)
Set e = sEmail.End(xlDown).Offset(1, 0)
e.Value = sEmailString(i)
Set p = nPoints.End(xlDown).Offset(1, 0)
p.Value = nPointVal
Dim s As Range ' Our summation range
Set s = Range(c.Offset(0, 5), c.Offset(0, c.EntireRow.Columns.Count - 1))
' c.Offset(1, 3).Formula = "=((" & s.Address & ""
End If
Next
End If
End Subの
「nPoints」の範囲を設定することはありません。列の最後のセルを見つけようとしている場合は、シートの最後の行から上に行くことをお勧めします。 – Kyle
さらに、もしあなたが「何もないならば何もしていない」と答えたい場合は – user3598756
「On Error Resume Next」はほとんど常に悪い考えです。それはしばしばOn Error Mislead Programmerとして機能する。バグがどこにあるかを見ることができるように削除してください。 –