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

質問編集履歴

8

修正

2020/03/30 02:35

投稿

fffu8
fffu8

スコア37

title CHANGED
File without changes
body CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
 
4
4
  ```VBA
5
+ '接続文字列
6
+ Const CONNECTION = "DRIVER={Microsoft ODBC for Oracle};CONNECTSTRING=XE;UID=system;PWD=systemsss;"
7
+
5
8
  '指定した場所のみ更新
6
9
  Sub Button3_Click()
7
10
 

7

修正

2020/03/30 02:35

投稿

fffu8
fffu8

スコア37

title CHANGED
File without changes
body CHANGED
@@ -1,6 +1,4 @@
1
- DBに接続して、ExcelにDBの情報をExcelに全件表示させて、Excelから一部書き換えて書き換えた所のみ、DBに書き込みしたいのですが、いちよプログラムは動くのですが、ループ(繰り返し)処理が更新するたび動くようにコードを書いてしまって、一回で書くことができません。色々考えたのですが進めないのでご質問させて頂きました。
1
+ DBに接続して、ExcelにDBの情報をExcelに全件表示させて、Excelから一部書き換えて書き換えた所のみ、DBに書き込みしたいのですが、いちよプログラムは動くのですが、ループ(繰り返し)処理が更新するたび動くようにコードを書いてしまって、一回で書くことができません。色々考えたのですが進めないのでご質問させて頂きました。お手数をおかけしますが、アドバイスよろしくお願い致します。
2
- 下記の太文字の所が関係している箇所です。
3
- お手数をおかけしますが、アドバイスよろしくお願い致します。
4
2
 
5
3
 
6
4
  ```VBA
@@ -35,16 +33,16 @@
35
33
  n = Cells(Rows.Count, "A").End(xlUp).row
36
34
 
37
35
 
38
- **For j = 1 To n**
36
+ For j = 1 To n
39
- ** For i = 1 To 3**
37
+ For i = 1 To 3
40
38
 
41
- ** If Cells(j, i + 1).Value <> arrRcd(i, j - 1) Then**
39
+ If Cells(j, i + 1).Value <> arrRcd(i, j - 1) Then
42
40
 
43
- ** strSQL = "update 社員テーブル1 set " _**
41
+ strSQL = "update 社員テーブル1 set " _
44
- ** + " 名前 ='" + Cells(j, 2).Value + "'" _**
42
+ + " 名前 ='" + Cells(j, 2).Value + "'" _
45
- ** + ",住所 ='" + Cells(j, 3).Value + "'" _**
43
+ + ",住所 ='" + Cells(j, 3).Value + "'" _
46
- ** + ",電話 ='" + Cells(j, 4).Value + "'" _**
44
+ + ",電話 ='" + Cells(j, 4).Value + "'" _
47
- **+ " where 社員NO = '" + CStr(j) + "'"**
45
+ + " where 社員NO = '" + CStr(j) + "'"
48
46
 
49
47
  With oraCmd
50
48
  .ActiveConnection = oraCon

6

修正

2020/03/30 02:34

投稿

fffu8
fffu8

スコア37

title CHANGED
File without changes
body CHANGED
@@ -35,16 +35,16 @@
35
35
  n = Cells(Rows.Count, "A").End(xlUp).row
36
36
 
37
37
 
38
- For j = 1 To n
38
+ **For j = 1 To n**
39
- For i = 1 To 3
39
+ ** For i = 1 To 3**
40
40
 
41
- If Cells(j, i + 1).Value <> arrRcd(i, j - 1) Then
41
+ ** If Cells(j, i + 1).Value <> arrRcd(i, j - 1) Then**
42
42
 
43
- strSQL = "update 社員テーブル1 set " _
43
+ ** strSQL = "update 社員テーブル1 set " _**
44
- + " 名前 ='" + Cells(j, 2).Value + "'" _
44
+ ** + " 名前 ='" + Cells(j, 2).Value + "'" _**
45
- + ",住所 ='" + Cells(j, 3).Value + "'" _
45
+ ** + ",住所 ='" + Cells(j, 3).Value + "'" _**
46
- + ",電話 ='" + Cells(j, 4).Value + "'" _
46
+ ** + ",電話 ='" + Cells(j, 4).Value + "'" _**
47
- + " where 社員NO = '" + CStr(j) + "'"
47
+ **+ " where 社員NO = '" + CStr(j) + "'"**
48
48
 
49
49
  With oraCmd
50
50
  .ActiveConnection = oraCon

5

コード修正

2020/03/30 02:33

投稿

fffu8
fffu8

スコア37

title CHANGED
File without changes
body CHANGED
@@ -35,16 +35,16 @@
35
35
  n = Cells(Rows.Count, "A").End(xlUp).row
36
36
 
37
37
 
38
- **For j = 1 To n**
38
+ For j = 1 To n
39
- ** For i = 1 To 3**
39
+ For i = 1 To 3
40
40
 
41
- ** If Cells(j, i + 1).Value <> arrRcd(i, j - 1) Then**
41
+ If Cells(j, i + 1).Value <> arrRcd(i, j - 1) Then
42
42
 
43
- ** strSQL = "update 社員テーブル1 set " _**
43
+ strSQL = "update 社員テーブル1 set " _
44
- ** + " 名前 ='" + Cells(j, 2).Value + "'" _**
44
+ + " 名前 ='" + Cells(j, 2).Value + "'" _
45
- ** + ",住所 ='" + Cells(j, 3).Value + "'" _**
45
+ + ",住所 ='" + Cells(j, 3).Value + "'" _
46
- ** + ",電話 ='" + Cells(j, 4).Value + "'" _**
46
+ + ",電話 ='" + Cells(j, 4).Value + "'" _
47
- ** + " where 社員NO = '" + CStr(j) + "'"**
47
+ + " where 社員NO = '" + CStr(j) + "'"
48
48
 
49
49
  With oraCmd
50
50
  .ActiveConnection = oraCon

4

修正

2020/03/30 02:28

投稿

fffu8
fffu8

スコア37

title CHANGED
File without changes
body CHANGED
@@ -3,8 +3,7 @@
3
3
  お手数をおかけしますが、アドバイスよろしくお願い致します。
4
4
 
5
5
 
6
-
7
- **VBA**
6
+ ```VBA
8
7
  '指定した場所のみ更新
9
8
  Sub Button3_Click()
10
9
 
@@ -34,8 +33,9 @@
34
33
 
35
34
  '最終行までの処理
36
35
  n = Cells(Rows.Count, "A").End(xlUp).row
37
-
36
+
37
+
38
- ** For j = 1 To n**
38
+ **For j = 1 To n**
39
39
  ** For i = 1 To 3**
40
40
 
41
41
  ** If Cells(j, i + 1).Value <> arrRcd(i, j - 1) Then**
@@ -61,4 +61,5 @@
61
61
  oraCon.Close
62
62
  Set oraCon = Nothing
63
63
 
64
- End Sub
64
+ End Sub
65
+ ```

3

修正

2020/03/30 02:26

投稿

fffu8
fffu8

スコア37

title CHANGED
File without changes
body CHANGED
@@ -4,9 +4,7 @@
4
4
 
5
5
 
6
6
 
7
-
8
-
9
- **コード**
7
+ **VBA**
10
8
  '指定した場所のみ更新
11
9
  Sub Button3_Click()
12
10
 

2

修正

2020/03/30 02:21

投稿

fffu8
fffu8

スコア37

title CHANGED
File without changes
body CHANGED
@@ -39,7 +39,7 @@
39
39
 
40
40
  ** For j = 1 To n**
41
41
  ** For i = 1 To 3**
42
- '行' '列' '列' '行'
42
+
43
43
  ** If Cells(j, i + 1).Value <> arrRcd(i, j - 1) Then**
44
44
 
45
45
  ** strSQL = "update 社員テーブル1 set " _**

1

コード修正

2020/03/30 01:48

投稿

fffu8
fffu8

スコア37

title CHANGED
File without changes
body CHANGED
@@ -1,10 +1,11 @@
1
1
  DBに接続して、ExcelにDBの情報をExcelに全件表示させて、Excelから一部書き換えて書き換えた所のみ、DBに書き込みしたいのですが、いちよプログラムは動くのですが、ループ(繰り返し)処理が更新するたび動くようにコードを書いてしまって、一回で書くことができません。色々考えたのですが進めないのでご質問させて頂きました。
2
- 下の太文字の所どのように改善たらよろしいでしょうか
2
+ の太文字の所が関係る箇所
3
3
  お手数をおかけしますが、アドバイスよろしくお願い致します。
4
4
 
5
5
 
6
6
 
7
7
 
8
+
8
9
  **コード**
9
10
  '指定した場所のみ更新
10
11
  Sub Button3_Click()
@@ -36,16 +37,16 @@
36
37
  '最終行までの処理
37
38
  n = Cells(Rows.Count, "A").End(xlUp).row
38
39
 
39
- ** For j = 1 To n
40
+ ** For j = 1 To n**
40
- For i = 1 To 3
41
+ ** For i = 1 To 3**
41
- '行' '列' '列' '行'
42
+ '行' '列' '列' '行'
42
- If Cells(j, i + 1).Value <> arrRcd(i, j - 1) Then
43
+ ** If Cells(j, i + 1).Value <> arrRcd(i, j - 1) Then**
43
44
 
44
- strSQL = "update 社員テーブル1 set " _
45
+ ** strSQL = "update 社員テーブル1 set " _**
45
- + " 名前 ='" + Cells(j, 2).Value + "'" _
46
+ ** + " 名前 ='" + Cells(j, 2).Value + "'" _**
46
- + ",住所 ='" + Cells(j, 3).Value + "'" _
47
+ ** + ",住所 ='" + Cells(j, 3).Value + "'" _**
47
- + ",電話 ='" + Cells(j, 4).Value + "'" _
48
+ ** + ",電話 ='" + Cells(j, 4).Value + "'" _**
48
- + " where 社員NO = '" + CStr(j) + "'"**
49
+ ** + " where 社員NO = '" + CStr(j) + "'"**
49
50
 
50
51
  With oraCmd
51
52
  .ActiveConnection = oraCon