Public Sub create_denpyo() write_no retsu = "b" '取引先で並び替え sort exe_create_denpyo retsu = "a" '番号で並び替え sort End Sub
Private Sub exe_create_denpyo() delete_denpyo Dim infoSh As Worksheet Dim infoGyo As Long Dim infoGyoMx As Long Dim shTo As Worksheet Dim shtoGyo As Long Dim dt As Date Dim sKaisha As String
Set infoSh = Worksheets("main") infoGyoMx = infoSh.Range("b1048576").End(xlUp).Row
For infoGyo = 2 To infoGyoMx If sKaisha <> infoSh.Range("b" & infoGyo).Value Then If infoGyo <> 2 Then keisen End If Worksheets("main1").Copy after:=Worksheets(Worksheets.Count) Set shTo = ActiveSheet sKaisha = infoSh.Range("b" & infoGyo).Value shTo.Name = sKaisha shtoGyo = 16
End If 'データ転記 shTo.Range("e" & shtoGyo).Value = infoSh.Range("d" & infoGyo).Value shTo.Range("f" & shtoGyo).Value = infoSh.Range("e" & infoGyo).Value shTo.Range("h" & shtoGyo).Value = infoSh.Range("f" & infoGyo).Value If infoSh.Range("g" & infoGyo).Value > 0 Then shTo.Range("i" & shtoGyo).Value = infoSh.Range("g" & infoGyo).Value Else shTo.Range("j" & shtoGyo).Value = infoSh.Range("g" & infoGyo).Value End If If shtoGyo = 16 Then shTo.Range("k" & shtoGyo).Value = infoSh.Range("g" & infoGyo).Value Else shTo.Range("k" & shtoGyo).Value = infoSh.Range("g" & infoGyo).Value + shTo.Range("k" & shtoGyo).Offset(-1).Value End If dt = infoSh.Range("c" & infoGyo).Value shTo.Range("b" & shtoGyo).Value = Right(Year(dt), 2) shTo.Range("c" & shtoGyo).Value = Month(dt) shTo.Range("d" & shtoGyo).Value = Day(dt) shtoGyo = shtoGyo + 1 Next keisen End Sub
Public Sub delete_denpyo() Dim ws As Worksheet Application.DisplayAlerts = False For Each ws In Worksheets If Left(ws.Name, 4) <> "main" Then ws.Delete End If Next Application.DisplayAlerts = True End Sub
Private Sub keisen() Dim inMx As Long inMx = Range("b1048576").End(xlUp).Row
With Range("B16:K" & inMx + 1) .Borders(xlDiagonalDown).LineStyle = xlNone .Borders(xlDiagonalUp).LineStyle = xlNone With .Borders(xlEdgeLeft) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = 1 End With With .Borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = 1 End With With .Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = 1 End With With .Borders(xlEdgeRight) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = 1 End With With .Borders(xlInsideVertical) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = 1 End With With .Borders(xlInsideHorizontal) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = 1 End With End With End Sub
Private Sub sort() Dim inMx As Long inMx = Range("b1048576").End(xlUp).Row
Range(retsu & "1").Select With ActiveWorkbook.Worksheets("main").sort.SortFields .Clear .Add _ Key:=Range(retsu & "2:" & retsu & inMx), _ Order:=xlAscending End With With ActiveWorkbook.Worksheets("main").sort .SetRange Range("A1:G" & inMx) .Header = xlYes .Apply End With End Sub
Private Sub write_no() Dim inGyo As Long Dim inMx As Long inMx = Range("b1048576").End(xlUp).Row
Range("a1").Value = "No." For inGyo = 2 To inMx Range("a" & inGyo).Value = inGyo - 1 Next
たかちゃんさんの投稿
(投稿ID: 4874)
いつもお世話になります。課題を提出致します。
どうぞ宜しくお願い致します。
Option Explicit
Dim retsu As String
Public Sub create_denpyo()
write_no
retsu = "b" '取引先で並び替え
sort
exe_create_denpyo
retsu = "a" '番号で並び替え
sort
End Sub
Private Sub exe_create_denpyo()
delete_denpyo
Dim infoSh As Worksheet
Dim infoGyo As Long
Dim infoGyoMx As Long
Dim shTo As Worksheet
Dim shtoGyo As Long
Dim dt As Date
Dim sKaisha As String
Set infoSh = Worksheets("main")
infoGyoMx = infoSh.Range("b1048576").End(xlUp).Row
For infoGyo = 2 To infoGyoMx
If sKaisha <> infoSh.Range("b" & infoGyo).Value Then
If infoGyo <> 2 Then
keisen
End If
Worksheets("main1").Copy after:=Worksheets(Worksheets.Count)
Set shTo = ActiveSheet
sKaisha = infoSh.Range("b" & infoGyo).Value
shTo.Name = sKaisha
shtoGyo = 16
End If
'データ転記
shTo.Range("e" & shtoGyo).Value = infoSh.Range("d" & infoGyo).Value
shTo.Range("f" & shtoGyo).Value = infoSh.Range("e" & infoGyo).Value
shTo.Range("h" & shtoGyo).Value = infoSh.Range("f" & infoGyo).Value
If infoSh.Range("g" & infoGyo).Value > 0 Then
shTo.Range("i" & shtoGyo).Value = infoSh.Range("g" & infoGyo).Value
Else
shTo.Range("j" & shtoGyo).Value = infoSh.Range("g" & infoGyo).Value
End If
If shtoGyo = 16 Then
shTo.Range("k" & shtoGyo).Value = infoSh.Range("g" & infoGyo).Value
Else
shTo.Range("k" & shtoGyo).Value = infoSh.Range("g" & infoGyo).Value + shTo.Range("k" & shtoGyo).Offset(-1).Value
End If
dt = infoSh.Range("c" & infoGyo).Value
shTo.Range("b" & shtoGyo).Value = Right(Year(dt), 2)
shTo.Range("c" & shtoGyo).Value = Month(dt)
shTo.Range("d" & shtoGyo).Value = Day(dt)
shtoGyo = shtoGyo + 1
Next
keisen
End Sub
Public Sub delete_denpyo()
Dim ws As Worksheet
Application.DisplayAlerts = False
For Each ws In Worksheets
If Left(ws.Name, 4) <> "main" Then
ws.Delete
End If
Next
Application.DisplayAlerts = True
End Sub
Private Sub keisen()
Dim inMx As Long
inMx = Range("b1048576").End(xlUp).Row
With Range("B16:K" & inMx + 1)
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
With .Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 1
End With
With .Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 1
End With
With .Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 1
End With
With .Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 1
End With
With .Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 1
End With
With .Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 1
End With
End With
End Sub
Private Sub sort()
Dim inMx As Long
inMx = Range("b1048576").End(xlUp).Row
Range(retsu & "1").Select
With ActiveWorkbook.Worksheets("main").sort.SortFields
.Clear
.Add _
Key:=Range(retsu & "2:" & retsu & inMx), _
Order:=xlAscending
End With
With ActiveWorkbook.Worksheets("main").sort
.SetRange Range("A1:G" & inMx)
.Header = xlYes
.Apply
End With
End Sub
Private Sub write_no()
Dim inGyo As Long
Dim inMx As Long
inMx = Range("b1048576").End(xlUp).Row
Range("a1").Value = "No."
For inGyo = 2 To inMx
Range("a" & inGyo).Value = inGyo - 1
Next
End Sub
たかちゃんさんのコメント
(コメントID: 6834)
小川 慶一さんのコメント
(コメントID: 6833)
おはようございます。
もはや、あまりコメントはないです...。先日お見せしたアレンジを参考にしてください。
ひとつだけ書くなら、Range.Borders について。
Borders(カッコ)となっていますね。コレクションです。
コレクションの要素は、それぞれ、以下の意味。
.Borders(xlDiagonalDown) '右肩下がり(の、斜め線)
.Borders(xlDiagonalUp) '右肩上がり(の、斜め線)
.Borders(xlEdgeLeft) '左側のエッジ(縁)
.Borders(xlEdgeTop) '天井のエッジ(縁)
.Borders(xlEdgeBottom) '底のエッジ(縁)
.Borders(xlEdgeRight) '右側のエッジ(縁)
.Borders(xlInsideVertical) '中の縦線
.Borders(xlInsideHorizontal) '中の水平線
エクセルのダイアログ[書式]→[罫線]で線を引く場所として選択できる項目と一致しています。
ps.
プログラムを投稿する際のヒントを以下に記載しています。
###このページは削除されました###
たかちゃんさんのコメント
(コメントID: 6836)
おはようございます。ありがとうございました。
プログラム提出の方法、了解しました。次回提出時から、[code][/code]で囲んで提出します。
> たかちゃんさん:
>
> おはようございます。
> もはや、あまりコメントはないです...。先日お見せしたアレンジを参考にしてください。
>
> ひとつだけ書くなら、Range.Borders について。
>
> Borders(カッコ)となっていますね。コレクションです。
> コレクションの要素は、それぞれ、以下の意味。
>
> .Borders(xlDiagonalDown) '右肩下がり(の、斜め線)
> .Borders(xlDiagonalUp) '右肩上がり(の、斜め線)
> .Borders(xlEdgeLeft) '左側のエッジ(縁)
> .Borders(xlEdgeTop) '天井のエッジ(縁)
> .Borders(xlEdgeBottom) '底のエッジ(縁)
> .Borders(xlEdgeRight) '右側のエッジ(縁)
> .Borders(xlInsideVertical) '中の縦線
> .Borders(xlInsideHorizontal) '中の水平線
>
> エクセルのダイアログ[書式]→[罫線]で線を引く場所として選択できる項目と一致しています。
>
> ps.
> プログラムを投稿する際のヒントを以下に記載しています。
> ###このページは削除されました###
>