スポンサードリンク | |
B | C | D | E | F | |
2 | 商品 | 2009年 | 2010年 | 2011年 | 四捨五入 |
3 | りんご | 5,548 | 4,975 | 5,843 | |
4 | みかん | 4,957 | 4,356 | 5,067 | |
5 | バナナ | 6,875 | 7,246 | 6,521 |
B | C | D | E | F | |
2 | 商品 | 2009年 | 2010年 | 2011年 | 切り上げ |
3 | りんご | 5,548 | 4,975 | 5,843 | |
4 | みかん | 4,957 | 4,356 | 5,067 | |
5 | バナナ | 6,875 | 7,246 | 6,521 |
B | C | D | E | F | |
2 | 商品 | 2009年 | 2010年 | 2011年 | 切り捨て |
3 | りんご | 5,548 | 4,975 | 5,843 | |
4 | みかん | 4,957 | 4,356 | 5,067 | |
5 | バナナ | 6,875 | 7,246 | 6,521 |
B | C | D | E | F | |
2 | 商品 | 2009年 | 2010年 | 2011年 | 四捨五入 |
3 | りんご | 5,548 | 4,975 | 5,843 | 5,455.3 |
4 | みかん | 4,957 | 4,356 | 5,067 | 4,793.3 |
5 | バナナ | 6,875 | 7,246 | 6,521 | 6,880.7 |
Sub test_01() Dim i As Long Dim ave As Double For i = 3 To 5 '平均値を求めます ave = Application.WorksheetFunction.Average(Range(Cells(i, 3), Cells(i, 5))) '四捨五入します Cells(i, 6).Value = Application.WorksheetFunction.Round(ave, 1) Next i Range("F3:F5").NumberFormatLocal = "#,##0.0" End Sub |
Sub test01a() Dim i As Long For i = 1 To 5 ’整数値に丸めます Cells(i, 2).Value = Round(Cells(i, 1)) Next i End Sub |
Sub test11() Dim i As Long, j As Long Dim goukei As Long, ave As Long For i = 3 To 5 goukei = 0 For j = 3 To 5 goukei = goukei + Cells(i, j) Next j ave = goukei * 100 / 3 + 5 Cells(i, 6).Value = Int(ave / 10) / 10 Next i Range("F3:F5").NumberFormatLocal = "#,##0.0" End Sub |
B | C | D | E | F | |
2 | 商品 | 2009年 | 2010年 | 2011年 | 切り上げ |
3 | りんご | 5,548 | 4,975 | 5,843 | 5,455.4 |
4 | みかん | 4,957 | 4,356 | 5,067 | 4,793.4 |
5 | バナナ | 6,875 | 7,246 | 6,521 | 6,880.7 |
Sub test_01() Dim i As Long Dim ave As Double For i = 3 To 5 '平均値を求めます ave = Application.WorksheetFunction.Average(Range(Cells(i, 3), Cells(i, 5))) '切り上げします Cells(i, 6).Value = Application.WorksheetFunction.RoundUp(ave, 1) Next i Range("F3:F5").NumberFormatLocal = "#,##0.0" End Sub |
Sub test12() Dim i As Long, j As Long Dim goukei As Currency, ave As Currency For i = 3 To 5 goukei = 0 For j = 3 To 5 goukei = goukei + Cells(i, j) Next j '平均値を求めます ave = goukei * 100 / 3 '切り上げします Cells(i, 9).Value = -Int(-ave / 10) / 10 Next i Range("F3:F5").NumberFormatLocal = "#,##0.0" End Sub |
B | C | D | E | F | |
2 | 商品 | 2009年 | 2010年 | 2011年 | 切り捨て |
3 | りんご | 5,548 | 4,975 | 5,843 | 5,455.3 |
4 | みかん | 4,957 | 4,356 | 5,067 | 4,793.3 |
5 | バナナ | 6,875 | 7,246 | 6,521 | 6,880.6 |
Sub test_01() Dim i As Long Dim ave As Double For i = 3 To 5 '平均値を求めます ave = Application.WorksheetFunction.Average(Range(Cells(i, 3), Cells(i, 5))) '切り捨てします Cells(i, 6).Value = Application.WorksheetFunction.RoundDown(ave, 1) Next i Range("F3:F5").NumberFormatLocal = "#,##0.0" End Sub |
Sub test13() Dim i As Long, j As Long Dim goukei As Currency, ave As Currency For i = 3 To 5 goukei = 0 For j = 3 To 5 goukei = goukei + Cells(i, j) Next j '平均値を求めます ave = goukei * 100 / 3 '切り捨てします Cells(i, 9).Value = Int(ave / 10) / 10 Next i Range("F3:F5").NumberFormatLocal = "#,##0.0" End Sub |
スポンサードリンク
PageViewCounter
Since2006/2/27