回答編集履歴

2

サンプルコードの追加

2018/02/20 12:18

投稿

hatena19
hatena19

スコア33757

test CHANGED
@@ -6,12 +6,38 @@
6
6
 
7
7
  With Workbooks(fileA).Worksheets(sheet1)
8
8
 
9
- .Range("G5:I23").Value = .Evaluate("G5:I23*3")
9
+ .Range("G5:I23").Value = .Evaluate("G5:I23*-2")
10
10
 
11
11
  End With
12
12
 
13
13
  ```
14
14
 
15
+ [Worksheet.Evaluate メソッド (Excel)](https://msdn.microsoft.com/ja-jp/VBA/Excel-VBA/articles/worksheet-evaluate-method-excel?f=255&MSPPError=-2147217396)
15
16
 
16
17
 
18
+
19
+ 下記のように簡略に記述することもできます。
20
+
21
+ ```vba
22
+
23
+ With Workbooks(fileA).Worksheets(sheet1)
24
+
25
+ .Range("G5:I23").Value = .[G5:I23*-2]
26
+
27
+ End With
28
+
29
+ ```
30
+
31
+ また、Forループを使った場合は、
32
+
33
+ ```vba
34
+
35
+ Dim r As Range
36
+
17
- [Worksheet.Evaluate メソッド (Excel)](https://msdn.microsoft.com/ja-jp/VBA/Excel-VBA/articles/worksheet-evaluate-method-excel?f=255&MSPPError=-2147217396)
37
+ For Each r In Workbooks(fileA).Worksheets(sheet1).Range("G5:I23")
38
+
39
+ v.Value = v.Value * -2
40
+
41
+ Next
42
+
43
+ ```

1

参考リンクの追加

2018/02/20 12:18

投稿

hatena19
hatena19

スコア33757

test CHANGED
@@ -11,3 +11,7 @@
11
11
  End With
12
12
 
13
13
  ```
14
+
15
+
16
+
17
+ [Worksheet.Evaluate メソッド (Excel)](https://msdn.microsoft.com/ja-jp/VBA/Excel-VBA/articles/worksheet-evaluate-method-excel?f=255&MSPPError=-2147217396)