2016-09-24 6 views
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の

+3

「nPoints」の範囲を設定することはありません。列の最後のセルを見つけようとしている場合は、シートの最後の行から上に行くことをお勧めします。 – Kyle

+1

さらに、もしあなたが「何もないならば何もしていない」と答えたい場合は – user3598756

+1

「On Error Resume Next」はほとんど常に悪い考えです。それはしばしばOn Error Mislead Programmerとして機能する。バグがどこにあるかを見ることができるように削除してください。 –

答えて

0

だから私は簡単な解決策が見つかりました:これはポイント値であるため、挿入された名前は、私たちが望むものである、上にあるのと同じ行を参照する

Set p = fName.End(xlDown).Offset(0, lEvent) 
      p.Value = nPointVal 

をこの人に関連するこれにいくつかの問題がある場合は、助言をください。

関連する問題