次のコマンドに移りません:VBAのループで立ち往生し、私は次のコードを書かれている
Public Sub SortMyData()
'approach: convert line to string and concatenate to that as it's a lot less picky than Excel's formats, then replace cell value with the new string.
' Excel will then define the string type as either Percentage or Scientific depending on the magnitude.
Dim i As Integer
Dim g As Integer
Dim N_Values As Integer
Dim IntermediateString As String
N_Values = Cells(1048576, 2).End(xlUp).Row 'retrieves the final filled row in column 2 (B)
For i = 6 To N_Values 'iteration loop from 6 (first row of value) to N_Values (last filled row)
If Cells(i, 2).NumberFormat <> "0.0%" Then
IntermediateString = Cells(i, 2).Value
Cells(i, 2).NumberFormat = "0.0%"
Cells(i, 2).Value = Cells(i, 2).Value/100
Else
MsgBox ("The Range of Cells Has Already Been Formated as Percentage")
End If
Next i
For g = 6 To N_Values 'iteration loop from 6 (first row of value) to N_Values (last filled row)
If Len(Cells(g, 3) > 3) Then
Cells(g, 3).Value = Cells(g, 3).Value/1000
Else
MsgBox ("Data is correct so no action will be taken")
End If
Next g
End Sub
コードが細かい実行されますがステートメントは、それだけで実行し続けるならば、それはsecont上に移動しません。最初のものとMsgBoxを表示する( "セルの範囲はすでにパーセンテージとして形成されています")ので、私はどこでミスをしたのか分かりません。 私は新人ですので、私の上で簡単に行く!
'N_Values'にはどのような値がありますか? F8モードでデバッグするか、このメソッドの最後の行を使用するN_Values =セル(Rows.Count、B ")End(xlUp).Row' –
どのような2番目のif文ですか? 2番目のループを意味しますか? 0とN_Values - 6のメッセージボックスの間のどこかを却下するまで実行されません。 – Comintern
上記と同様。行6からN_Valuesにループしていて、次に列3でN_Valuesをループしています。もう一度行3を実行すると、もう一方を実行する前にすべて完了します。両方のIF文を最初のループの中に入れて、2番目のものを削除する... – Dave