teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

コード例追加

2017/08/28 02:51

投稿

otn
otn

スコア86349

answer CHANGED
@@ -1,3 +1,22 @@
1
1
  `Cells`と、変数名がごっちゃになっています。
2
+ `End If`が無いし。
2
3
 
3
- あと、変数を宣言するなら、型も指定した方が良いです。
4
+ あと、変数を宣言するなら、型も指定した方が良いです。
5
+
6
+ #コード例
7
+ ```VBA
8
+ Sub 金種計算()
9
+ Dim 添字 As Integer, 金額 As Long, 金種 As Integer
10
+
11
+ 金額 = Cells(6, 4)
12
+ 添字 = 2
13
+
14
+ Do While Cells(3, 添字).Value <> ""
15
+ If 金額 >= Cells(3, 添字) Then
16
+ Cells(4, 添字) = 金額 \ Cells(3, 添字)
17
+ 金額 = 金額 - Cells(4, 添字) * Cells(3, 添字)
18
+ End If
19
+ 添字 = 添字 + 1
20
+ Loop
21
+ End Sub
22
+ ```