2017-05-18 8 views
-1

userformを作成しましたが、私は少し難解です。 userformの値が選択されている場合は、特定の値になるようにテキストを設定するにはどうすればよいですか?私がしたいことは、コンボボックスのSP.Valueが "Yes"の場合、ST.ValueがYesの場合、iRowのテキスト全体が赤色になりたいのですが、iRow全体が青色になりたいと思っています。私はこれが意味をなさないと思いますか? SP.ValueとST.Valueはのちょうどのオプションでユーザーフォーム内の両方のコンボボックスです「はい/いいえ」私は取得していますVBAを使用して書式を設定するユーザーフォーム

Private Sub NL_Click() 

Dim iRow As Long 
Dim ws As Worksheet 

Set ws = Worksheets("Sp Br") 

iRow = ws.Cells.Find(what:="*", SearchOrder:=xlRows, _ 
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1 

If SP.Value = "Yes" Then 
    With iRow 
    .colour = -16776961 
    .TintAndShade = 0 
    Sheets("Spec Break").Range("B2").Value = Customer.Value 
    Sheets("Spec Break").Range("B3").Value = Project.Value 
    Sheets("Spec Break").Range("B4").Value = Format(Now, ["DD/MM/YYYY"]) 
    Sheets("Spec Break").Range("B5").Value = RSM.Value 
    ws.Cells(iRow, 1).Value = Cf.Value 
    ws.Cells(iRow, 2).Value = RT.Value 
    ws.Cells(iRow, 3).Value = MEqu.Value 
    ws.Cells(iRow, 4).Value = hmm.Value 
    ws.Cells(iRow, 5).Value = wmm.Value 
    ws.Cells(iRow, 6).Value = Opt.Value 
    ws.Cells(iRow, 7).Value = Tap.Value 
    ws.Cells(iRow, 8).Value = Fing.Value 
    ws.Cells(iRow, 9).Value = col.Value 
    ws.Cells(iRow, 10).Value = Pr.Value 
    ws.Cells(iRow, 11).Value = Qt.Value 
    End With 
End If 

'Insert a row beneath the data to push down footer image 
     ActiveCell.Offset(1).EntireRow.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromRightOrAbove 
     ActiveCell.EntireRow.Copy 
     ActiveCell.Offset(1).EntireRow.PasteSpecial xlPasteFormats 
     Application.CutCopyMode = False 

'clear form values 
    CustRef.Value = "" 
    RadType.Value = "" 
    MysonEquiv.Value = "" 
    heightmm.Value = "" 
    widthmm.Value = "" 
    Output.Value = "" 
    Tapping.Value = "" 
    Fixing.Value = "" 
    colour.Value = "" 
    Price.Value = "" 
    Qty.Value = "" 

End Sub 
ユーザー定義型、オブジェクトまたは変異体でなければならないオブジェクトとエラー
+1

おそらく、おそらくエラーメッセージが問題をよくまとめています。あなたはLongである 'iRow'を使って' With'ステートメントに従っています。おそらくあなたは '行(iRow)'を意味するでしょうか? – SJR

答えて

1

SJRはあなたのiRowが長い数値12345578などを持っていることを指摘していますので、実際には何のこともできません。あなたはすでにws.cellsコードを持っています。 iRowは行番号を保持し、列を指定します。だから、ブロックを使用してを削除し、最初の数行のための細胞と行の参照を使用します。

If SP.Value = "Yes" Then 
    Rows(iRow).colour = -16776961 
    Rows(iRow).TintAndShade = 0 
    Sheets("Spec Break").Range("B2").Value = Customer.Value 
    Sheets("Spec Break").Range("B3").Value = Project.Value 
    Sheets("Spec Break").Range("B4").Value = Format(Now, ["DD/MM/YYYY"]) 
    Sheets("Spec Break").Range("B5").Value = RSM.Value 
    ws.Cells(iRow, 1).Value = Cf.Value 

' etc 
0

申し訳ありませんが、私はそれを下にクリックするという意味ではありませんでした...私は答えを引き上げてきました。悲しいことに、私が正しい方向に私を送ってくれてありがとうございます。悲しいことに、解決策はまだエラー2を返しました。カラーパレットとMSDNを調べた後、私のコードを以下に変更することができました。

Private Sub NL_Click() 

Dim iRow As Long 
Dim ws As Worksheet 

Set ws = Worksheets("Spec Break") 


iRow = ws.Cells.Find(what:="*", SearchOrder:=xlRows, _ 
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1 


If Specials.Value = "Yes" Then 
    With Rows(iRow) 
     .Font.Color = RGB(255, 0, 0) 
      Sheets("Spec Break").Range("B2").Value = Customer.Value 
      Sheets("Spec Break").Range("B3").Value = Project.Value 
      Sheets("Spec Break").Range("B4").Value = Format(Now, ["DD/MM/YYYY"]) 
      Sheets("Spec Break").Range("B5").Value = RSM.Value 
       ws.Cells(iRow, 1).Value = Cf.Value 
       ws.Cells(iRow, 2).Value = RT.Value 
       ws.Cells(iRow, 3).Value = MEqu.Value 
       ws.Cells(iRow, 4).Value = hmm.Value 
       ws.Cells(iRow, 5).Value = wmm.Value 
       ws.Cells(iRow, 6).Value = Opt.Value 
       ws.Cells(iRow, 7).Value = Tap.Value 
       ws.Cells(iRow, 8).Value = Fix.Value 
       ws.Cells(iRow, 9).Value = col.Value 
       ws.Cells(iRow, 10).Value = Pr.Value 
       ws.Cells(iRow, 11).Value = Qt.Value 
    End With 
End If 

End Sub 
関連する問題