1
範囲内の多くのセルに単位を追加しようとしています。以下は私がいる場所で、型の不一致エラーが発生し続けます:
Dim r As Range, cell As Range
Set r = Range("D2:E1000")
For Each cell In r
If cell.Value > 0 Then
cell.Value = cell.Value + 1
End If
Next
1
範囲内の多くのセルに単位を追加しようとしています。以下は私がいる場所で、型の不一致エラーが発生し続けます:
Dim r As Range, cell As Range
Set r = Range("D2:E1000")
For Each cell In r
If cell.Value > 0 Then
cell.Value = cell.Value + 1
End If
Next
ここに別の方法があります
Sub Sandwich()
Dim rTemp As Range
Dim rTarget As Range
Dim sNumFmt As String
'Define the ranges
Set rTemp = Sheet2.Cells(Sheet2.Rows.Count, 1).End(xlUp).Offset(1, 0)
Set rTarget = Sheet2.Range("D2:E1000")
'store a temporary value and the current number format
rTemp.Value = 1
sNumFmt = rTarget.Cells(1).NumberFormat
'copy and paste special-add
rTemp.Copy
rTarget.PasteSpecial , xlPasteSpecialOperationAdd
'get rid of the temp and reapply the format
rTemp.ClearContents
rTarget.NumberFormat = sNumFmt
End Sub
最も簡単な方法で停止するOK, I'm trying to add a unit of "1" to many cells in a range.
のは、多くの場合、VBA やコードを使用しないことです。スプレッドシートのどこかに挿入1
し、そのセルをコピーし、関心のある範囲を選択して、Operation Add で貼り付けます。その後1
、 を削除できます。
どうですか:
Sub marine()
Dim r As Range, cell As Range
Set r = Range("D2:E1000")
For Each cell In r
If IsNumeric(cell.Value) Then
If cell.Value > 0 Then
cell.Value = cell.Value + 1
End If
Else
MsgBox "Cell " & cell.Address(0, 0) & " does not have a number"
Exit Sub
End If
Next
End Sub
Dim r As Range, cell As Range
Set r = Range("D2:E1000")
For Each cell In r
If cell > 0 Then
cell.Value = cell.Value + 1
End If
Next
私のために働いています、おそらくIFセル= 0が必要ですか??? 私があなたの質問に答えたかどうかを確認するためにあなたのコメントを待っています。