|
ゴメン勘違いしました
こんなので?
Sub Macro()
'転記先頭行位置
Const clngPostT As Long = 15
'転記最終行位置
Const clngPostE As Long = 22
Dim i As Long
' Dim mySh1 As Worksheet
Dim mySh2 As Worksheet
Dim myRow As Long
' Dim actRow As Long
Dim j As Long
Dim rngMark As Range
Dim rngElement As Range
Dim strPrompt As String
If TypeName(Selection) <> "Range" Then
strPrompt = "セル範囲を選択して下さい"
GoTo Wayout
End If
Set rngMark = Intersect(Selection, Columns("A"))
If rngMark Is Nothing Then
strPrompt = "A列のセルを選択して下さい(終了)"
GoTo Wayout
End If
' actRow = ActiveCell.Row
If Sheets(Sheets.Count).Name <> "New" Then
Sheets("発注書").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = Format(Now, "yymmdd_hhmmss")
End If
' Set mySh1 = Sheets("一覧")
Set mySh2 = ActiveSheet
' For i = 15 To 22
For i = clngPostT To clngPostE
If mySh2.Range("A" & i) = "" Then
' myRow = i
Exit For
End If
Next i
' If myRow = 0 Then
If i > clngPostE Then
strPrompt = "空欄がありません!"
GoTo Wayout
End If
' Exit Sub '此処でSubから無条件で抜けているので、以降のコードは実行されないよ??
For Each rngElement In rngMark
With mySh2
.Range("F" & i).Value = rngElement.Value
.Range("A" & i).Value = rngElement.Offset(, 1).Value
.Range("G" & i).Value = rngElement.Offset(, 2).Value
.Range("H" & i).Value = rngElement.Offset(, 3).Value
.Range("I" & i).Value = rngElement.Offset(, 9).Value
End With
i = i + 1
If i > clngPostE Then
Exit For
End If
Next rngElement
With mySh2
.Range("G11").Value = rngMark.Cells(1, "E").Value
.Range("A3").Value = rngMark.Cells(1, "F").Value
.Range("A1").Value = rngMark.Cells(1, "G").Value
.Range("I2").Value = rngMark.Cells(1, "H").Value
.Range("I12").Value = rngMark.Cells(1, "I").Value
.Range("B23").Value = rngMark.Cells(1, "K").Value
.Range("I5").Value = rngMark.Cells(1, "L").Value
End With
mySh2.Select
Wayout:
' Set mySh1 = Nothing
Set mySh2 = Nothing
Set rngMark = Nothing
MsgBox strPrompt, vbInformation
End Sub
|
|