回答編集履歴

3

実際の範囲へ合わせこみ

2021/04/09 01:55

投稿

Third_Kei
Third_Kei

スコア65

test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  以下はCSVへの出力を行う手順をざっくり書いたものです
6
6
 
7
- 高速化、データ整形などの改善点は大量にありますが、参考までに
7
+ 高速化、データ整形などの改善点はいくつかありますが、参考までに
8
8
 
9
9
 
10
10
 
@@ -14,39 +14,39 @@
14
14
 
15
15
 
16
16
 
17
- Dim ws As Worksheet
17
+ Dim ws As Worksheet
18
18
 
19
- Set ws = ThisWorkbook.Worksheets(1)
19
+ Set ws = ThisWorkbook.Worksheets(1)
20
20
 
21
+
21
22
 
23
+ Dim csvFile As String
22
24
 
23
- Dim csvFile As String
25
+ csvFile = ActiveWorkbook.Path & "\data.csv"
24
26
 
25
- csvFile = ActiveWorkbook.Path & "\テスト.csv"
27
+ Open csvFile For Output As #1
26
28
 
27
- Open csvFile For Output As #1
29
+ Dim v As Variant
28
30
 
29
- Dim i As Long, j As Long
31
+ v = Range(Cells(5, 26), Cells(58, 27))
30
32
 
33
+ Dim i As Long, j As Long
31
34
 
35
+ For i = 5 - 4 To 58 - 4 '1始まりに調整
32
36
 
33
- For i = 1 To 10
37
+ For j = 26 - 25 To 27 - 25 '1始まりに調整
34
38
 
35
- For j = 1 To 10
39
+ Print #1, v(i, j) & ",";
36
40
 
41
+ Next
42
+
37
- Print #1, ws.Cells(i, j).Value & ",";
43
+ Print #1, vbCr;
38
44
 
39
45
  Next
40
46
 
41
- Print #1, vbCr;
47
+ Close #1
42
48
 
43
- Next
49
+
44
-
45
-
46
-
47
- Close #1
48
-
49
-
50
50
 
51
51
  MsgBox "data.csvに書き出しました"
52
52
 

2

画像削除

2021/04/09 01:55

投稿

Third_Kei
Third_Kei

スコア65

test CHANGED
@@ -55,13 +55,3 @@
55
55
  End Sub
56
56
 
57
57
  ```
58
-
59
- ###実行元Excel
60
-
61
- ![上記プログラム実行元ファイル](b3ce0fc2e70eee0823ec93c0af4423d8.png)
62
-
63
-
64
-
65
- ###実行後CSV
66
-
67
- ![出力CSV](af9a5aafdc30cd20c2a8a040d49cbf46.png)

1

画像の追記

2021/04/09 01:38

投稿

Third_Kei
Third_Kei

スコア65

test CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  Dim csvFile As String
24
24
 
25
- csvFile = ActiveWorkbook.Path & "\data.csv"
25
+ csvFile = ActiveWorkbook.Path & "\テスト.csv"
26
26
 
27
27
  Open csvFile For Output As #1
28
28
 
@@ -55,3 +55,13 @@
55
55
  End Sub
56
56
 
57
57
  ```
58
+
59
+ ###実行元Excel
60
+
61
+ ![上記プログラム実行元ファイル](b3ce0fc2e70eee0823ec93c0af4423d8.png)
62
+
63
+
64
+
65
+ ###実行後CSV
66
+
67
+ ![出力CSV](af9a5aafdc30cd20c2a8a040d49cbf46.png)