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

質問編集履歴

25

2021/07/12 23:36

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,4 @@
1
- **分からない点はsheet2.Cells(row2, col2) = colect.item(i) 以降のコレクトの値をループさせてブックに表示する方法****
1
+ **分からない点はsheet2.Cells(row2, col2) = colect.item(i) コレクトの値をループさせて別のブックのセルに表示する方法****
2
2
  Const ST_ROW As Long=4
3
3
  Const ST_COL As Long=2
4
4
  Sub 数と日付()

24

2021/07/12 23:36

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
@@ -18,7 +18,8 @@
18
18
 
19
19
  Set Wb2 = Workbooks("Book11.xlsx") 'コピー元(参照する)ブック Set
20
20
  sheet1=Wb2.Worksheets("コピー元")
21
- Set sheet2=Wb1.Worksheets("コピー先") lastRow=sheet1.Cells(Rows.Count, ST_COL).End(xlUp).row lastcol=sheet1.Cells(ST_ROW, Columns.Count).End(xlToLeft).Column ReDim ary(0, lastcol - ST_COL) For row=ST_ROW To lastRow
21
+ Set sheet2=Wb1.Worksheets("コピー先")
22
+ lastRow=sheet1.Cells(Rows.Count, ST_COL).End(xlUp).row lastcol=sheet1.Cells(ST_ROW, Columns.Count).End(xlToLeft).Column ReDim ary(0, lastcol - ST_COL) For row=ST_ROW To lastRow
22
23
  If sheet1.Cells(row, 4) >= 2 Then
23
24
  For col=ST_COL To lastcol
24
25
  ary(index, index2) = sheet1.Cells(row, col)

23

2021/07/12 23:34

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
File without changes

22

2021/07/12 23:34

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
File without changes

21

2021/07/12 23:34

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
@@ -17,7 +17,8 @@
17
17
  Set Wb1=ThisWorkbook 'コピー先ブック
18
18
 
19
19
  Set Wb2 = Workbooks("Book11.xlsx") 'コピー元(参照する)ブック Set
20
- sheet1=Wb2.Worksheets("コピー元") Set sheet2=Wb1.Worksheets("コピー先") lastRow=sheet1.Cells(Rows.Count, ST_COL).End(xlUp).row lastcol=sheet1.Cells(ST_ROW, Columns.Count).End(xlToLeft).Column ReDim ary(0, lastcol - ST_COL) For row=ST_ROW To lastRow
20
+ sheet1=Wb2.Worksheets("コピー元")
21
+ Set sheet2=Wb1.Worksheets("コピー先") lastRow=sheet1.Cells(Rows.Count, ST_COL).End(xlUp).row lastcol=sheet1.Cells(ST_ROW, Columns.Count).End(xlToLeft).Column ReDim ary(0, lastcol - ST_COL) For row=ST_ROW To lastRow
21
22
  If sheet1.Cells(row, 4) >= 2 Then
22
23
  For col=ST_COL To lastcol
23
24
  ary(index, index2) = sheet1.Cells(row, col)

20

2021/07/12 23:34

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
@@ -14,8 +14,10 @@
14
14
  Dim index As Long
15
15
  Dim index2 As Long
16
16
  Dim colect As Collection, item As Variant Set colect=New Collection sPath="Book11.xlsx"
17
- Set Wb1=ThisWorkbook 'コピー先ブック
18
- Set Wb2 = Workbooks("Book11.xlsx") 'コピー元(参照する)ブック Set sheet1=Wb2.Worksheets("コピー元") Set sheet2=Wb1.Worksheets("コピー先") lastRow=sheet1.Cells(Rows.Count, ST_COL).End(xlUp).row lastcol=sheet1.Cells(ST_ROW, Columns.Count).End(xlToLeft).Column ReDim ary(0, lastcol - ST_COL) For row=ST_ROW To lastRow
17
+ Set Wb1=ThisWorkbook 'コピー先ブック
18
+
19
+ Set Wb2 = Workbooks("Book11.xlsx") 'コピー元(参照する)ブック Set
20
+ sheet1=Wb2.Worksheets("コピー元") Set sheet2=Wb1.Worksheets("コピー先") lastRow=sheet1.Cells(Rows.Count, ST_COL).End(xlUp).row lastcol=sheet1.Cells(ST_ROW, Columns.Count).End(xlToLeft).Column ReDim ary(0, lastcol - ST_COL) For row=ST_ROW To lastRow
19
21
  If sheet1.Cells(row, 4) >= 2 Then
20
22
  For col=ST_COL To lastcol
21
23
  ary(index, index2) = sheet1.Cells(row, col)

19

2021/07/12 23:34

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
@@ -15,7 +15,7 @@
15
15
  Dim index2 As Long
16
16
  Dim colect As Collection, item As Variant Set colect=New Collection sPath="Book11.xlsx"
17
17
  Set Wb1=ThisWorkbook 'コピー先ブック
18
- Set Wb2 = Workbooks("Book11.xlsx") 'コピー元(参照する)ブック Set sheet1=Wb2.Worksheets("コピー元") Set sheet2=Wb1.Worksheets("コピー先") lastRow=sheet1.Cells(Rows.Count, ST_COL).End(xlUp).row lastcol=sheet1.Cells(ST_ROW, Columns.Count).End(xlToLeft).Column ReDim ary(0, lastcol - ST_COL) For row=ST_ROW To lastRow '縦の最初と末尾
18
+ Set Wb2 = Workbooks("Book11.xlsx") 'コピー元(参照する)ブック Set sheet1=Wb2.Worksheets("コピー元") Set sheet2=Wb1.Worksheets("コピー先") lastRow=sheet1.Cells(Rows.Count, ST_COL).End(xlUp).row lastcol=sheet1.Cells(ST_ROW, Columns.Count).End(xlToLeft).Column ReDim ary(0, lastcol - ST_COL) For row=ST_ROW To lastRow
19
19
  If sheet1.Cells(row, 4) >= 2 Then
20
20
  For col=ST_COL To lastcol
21
21
  ary(index, index2) = sheet1.Cells(row, col)

18

2021/07/12 23:33

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
@@ -1,5 +1,4 @@
1
- ** 分からない点はsheet2.Cells(row2, col2) = colect.item(i) 以降のコレクトの値をループさせてブックに表示する方法
1
+ **分からない点はsheet2.Cells(row2, col2) = colect.item(i) 以降のコレクトの値をループさせてブックに表示する方法****
2
- **
3
2
  Const ST_ROW As Long=4
4
3
  Const ST_COL As Long=2
5
4
  Sub 数と日付()

17

2021/07/12 23:33

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
File without changes

16

2021/07/12 23:32

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
File without changes

15

2021/07/12 23:32

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
@@ -1,5 +1,5 @@
1
- 分からない点はsheet2.Cells(row2, col2) = colect.item(i) 以降のコレクトの値をループさせてブックに表示する方法
1
+ ** 分からない点はsheet2.Cells(row2, col2) = colect.item(i) 以降のコレクトの値をループさせてブックに表示する方法
2
-
2
+ **
3
3
  Const ST_ROW As Long=4
4
4
  Const ST_COL As Long=2
5
5
  Sub 数と日付()

14

2021/07/12 23:32

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
File without changes

13

2021/07/12 23:30

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
File without changes

12

2021/07/12 23:30

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
File without changes

11

2021/07/12 23:30

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
File without changes

10

2021/07/12 23:30

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
File without changes

9

2021/07/12 23:30

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
File without changes

8

2021/07/12 23:30

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,34 @@
1
1
  分からない点はsheet2.Cells(row2, col2) = colect.item(i) 以降のコレクトの値をループさせてブックに表示する方法
2
2
 
3
+ Const ST_ROW As Long=4
4
+ Const ST_COL As Long=2
5
+ Sub 数と日付()
6
+ Dim Wb1 As Workbook
7
+ Dim Wb2 As Workbook
8
+ Dim ary() As String
9
+ Dim row As Long
10
+ Dim col As Long
11
+ Dim sheet1 As Worksheet
12
+ Dim sheet2 As Worksheet
13
+ Dim lastRow As Long
14
+ Dim lastcol As Long
15
+ Dim index As Long
16
+ Dim index2 As Long
17
+ Dim colect As Collection, item As Variant Set colect=New Collection sPath="Book11.xlsx"
18
+ Set Wb1=ThisWorkbook 'コピー先ブック
19
+ Set Wb2 = Workbooks("Book11.xlsx") 'コピー元(参照する)ブック Set sheet1=Wb2.Worksheets("コピー元") Set sheet2=Wb1.Worksheets("コピー先") lastRow=sheet1.Cells(Rows.Count, ST_COL).End(xlUp).row lastcol=sheet1.Cells(ST_ROW, Columns.Count).End(xlToLeft).Column ReDim ary(0, lastcol - ST_COL) For row=ST_ROW To lastRow '縦の最初と末尾
20
+ If sheet1.Cells(row, 4) >= 2 Then
21
+ For col=ST_COL To lastcol
22
+ ary(index, index2) = sheet1.Cells(row, col)
23
+ index2=index2+1
24
+ Next colect.Add ary End If index2 = 0
25
+ Next Dim row2 As Long
26
+ Dim col2 As Long
27
+ Dim i As Long
3
28
 
4
- Const ST_ROW As Long = 4Const ST_COL As Long = 2Sub 数と日付() Dim Wb1 As Workbook Dim Wb2 As Workbook Dim ary() As String Dim row As Long Dim col As Long Dim sheet1 As Worksheet Dim sheet2 As Worksheet Dim lastRow As Long Dim lastcol As Long Dim index As Long Dim index2 As Long Dim colect As Collection, item As Variant Set colect = New Collection sPath = "Book11.xlsx" Set Wb1 = ThisWorkbook 'コピー先ブック Set Wb2 = Workbooks("Book11.xlsx") 'コピー元(参照する)ブック Set sheet1 = Wb2.Worksheets("コピー元") Set sheet2 = Wb1.Worksheets("コピー先") lastRow = sheet1.Cells(Rows.Count, ST_COL).End(xlUp).row lastcol = sheet1.Cells(ST_ROW, Columns.Count).End(xlToLeft).Column ReDim ary(0, lastcol - ST_COL) For row = ST_ROW To lastRow '縦の最初と末尾 If sheet1.Cells(row, 4) >= 2 Then '2以上の時 For col = ST_COL To lastcol '横の最初と末 ary(index, index2) = sheet1.Cells(row, col) '価を格納する index2 = index2 + 1 '次の横の価に Next colect.Add ary End If index2 = 0 '横の価をリセット Next Dim row2 As Long Dim col2 As Long Dim i As Long For row2 = 2 To colect.Count For col2 = 1 To 4 sheet2.Cells(row2, col2) = colect.item(i) col2 = col2 + 1 Next col2 = 0 Next sheet2.Range("A1:D1").Value = sheet1.Range("B3:E3").Value With ActiveSheet .Range("A1").Sort key1:=.Range("D1"), order1:=xlAscending, Header:=xlYes End WithEnd Sub
29
+ **ここから下が不明点**
30
+ For row2=2 To colect.Count
31
+ For col2=1 To 4 sheet2.Cells(row2,
32
+ col2)=colect.item(i)
33
+ col2=col2+1 Next col2=0 Next
34
+ sheet2.Range("A1:D1").Value=sheet1.Range("B3:E3").Value With ActiveSheet .Range("A1").Sort key1:=.Range("D1"), order1:=xlAscending, Header:=xlYes End WithEnd Sub

7

2021/07/12 23:30

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
File without changes

6

2021/07/12 12:41

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
File without changes

5

2021/07/12 12:41

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
File without changes

4

2021/07/12 12:41

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
File without changes

3

2021/07/12 12:41

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
File without changes

2

2021/07/12 12:41

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
File without changes

1

2021/07/12 12:41

投稿

maxsbezitaburu
maxsbezitaburu

スコア0

title CHANGED
File without changes
body CHANGED
@@ -1,1 +1,4 @@
1
+ 分からない点はsheet2.Cells(row2, col2) = colect.item(i) 以降のコレクトの値をループさせてブックに表示する方法
2
+
3
+
1
4
  Const ST_ROW As Long = 4Const ST_COL As Long = 2Sub 数と日付() Dim Wb1 As Workbook Dim Wb2 As Workbook Dim ary() As String Dim row As Long Dim col As Long Dim sheet1 As Worksheet Dim sheet2 As Worksheet Dim lastRow As Long Dim lastcol As Long Dim index As Long Dim index2 As Long Dim colect As Collection, item As Variant Set colect = New Collection sPath = "Book11.xlsx" Set Wb1 = ThisWorkbook 'コピー先ブック Set Wb2 = Workbooks("Book11.xlsx") 'コピー元(参照する)ブック Set sheet1 = Wb2.Worksheets("コピー元") Set sheet2 = Wb1.Worksheets("コピー先") lastRow = sheet1.Cells(Rows.Count, ST_COL).End(xlUp).row lastcol = sheet1.Cells(ST_ROW, Columns.Count).End(xlToLeft).Column ReDim ary(0, lastcol - ST_COL) For row = ST_ROW To lastRow '縦の最初と末尾 If sheet1.Cells(row, 4) >= 2 Then '2以上の時 For col = ST_COL To lastcol '横の最初と末 ary(index, index2) = sheet1.Cells(row, col) '価を格納する index2 = index2 + 1 '次の横の価に Next colect.Add ary End If index2 = 0 '横の価をリセット Next Dim row2 As Long Dim col2 As Long Dim i As Long For row2 = 2 To colect.Count For col2 = 1 To 4 sheet2.Cells(row2, col2) = colect.item(i) col2 = col2 + 1 Next col2 = 0 Next sheet2.Range("A1:D1").Value = sheet1.Range("B3:E3").Value With ActiveSheet .Range("A1").Sort key1:=.Range("D1"), order1:=xlAscending, Header:=xlYes End WithEnd Sub