ここに、列 A の一意のセルごとに新しいテンプレート シートを作成するコードがあります。次に、列 E、F、L、および O を、新しく作成されたテンプレート シートの適切な位置に配布します。
ただし、データシートの列 E の値を、作成されたテンプレート シートの末尾に配置します。値の空白セルの開始である行4から開始するようにするにはどうすればよいですか。
また、テンプレート シートに列 F の値が既にある場合、テンプレートに同じ行を配置しない新しいコマンドを誰かが手伝ってくれる場合。
Sub Redemption()
Dim wsDatatable As Worksheet
Dim wsTempelate As Worksheet
Dim rangeFound As Range
Dim rangeNames As Range
Dim NameCells As Range
Dim stringFirst As String
Dim stringNames As String
Dim stringUniqueNames As String
Set wsDatatable = Sheets("DATA INPUT TABLE")
Set wsTempelate = Sheets("CLASS GROUPING ID")
Set rangeNames = wsDatatable.Range("A2", wsDatatable.Cells(Rows.Count, "A").End(xlUp))
For Each NameCells In rangeNames.Cells
If InStr(1, "|" & stringUniqueNames & "|", "|" & NameCells.Text & "|", vbTextCompare) = 0 Then
stringUniqueNames = stringUniqueNames & "|" & NameCells.Text
Set rangeFound = rangeNames.Find(NameCells.Text, rangeNames.Cells(rangeNames.Cells.Count), xlValues, xlWhole)
If Not rangeFound Is Nothing Then
stringFirst = rangeFound.Address
stringNames = NameCells.Text
stringNames = Trim(Left(WorksheetFunction.Trim(stringNames), 31))
If Evaluate("IsRef('" & stringNames & "'!A1)") = False Then
wsTempelate.Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = stringNames
End If
With Sheets(stringNames)
Do
If LCase(wsDatatable.Cells(rangeFound.Row, "I").Text) = "full liquidation" Or LCase(wsDatatable.Cells(rangeFound.Row, "I").Text) = "redemption" Then
.Cells(Rows.Count, "A").End(xlUp).Offset(1).Value = wsDatatable.Cells(rangeFound.Row, "E").Value
.Cells(Rows.Count, "B").End(xlUp).Offset(1).Value = wsDatatable.Cells(rangeFound.Row, "F").Value
.Cells(Rows.Count, "C").End(xlUp).Offset(1).Value = wsDatatable.Cells(rangeFound.Row, "B").Value
.Cells(Rows.Count, "D").End(xlUp).Offset(1).Value = wsDatatable.Cells(rangeFound.Row, "O").Value
.Cells(Rows.Count, "E").End(xlUp).Offset(1).Value = wsDatatable.Cells(rangeFound.Row, "L").Value
End If
Set rangeFound = rangeNames.Find(NameCells.Text, rangeFound, xlValues, xlWhole)
Loop While rangeFound.Address <> stringFirst
End With
End If
End If
Next NameCells
Set wsDatatable = Nothing
Set wsTempelate = Nothing
Set rangeFound = Nothing
Set rangeNames = Nothing
Set NameCells = Nothing
End Sub