カラム内の特定の値を持つ人とマッチするマクロを処理しています。ただし、マクロの一部では、各自が割り当てた合計から人の割合を削除することができます。カラムから値の最初のn個のインスタンスを削除します
Data | Name
--------------
1234 | Person1
3456 | Person1
8768 | Person2
0878 | Person3
4132 | Person5
0986 | Person1
0182 | Person5
0197 | Person4
4501 | Person2
4132 | Person2
8126 | Person4
0172 | Person4
0911 | Person4
0751 | Person3
6681 | Person1
8819 | Person2
マクロの関連部分は、これまでのところ、次のようになります:ユーザーは、個人の名前と希望%に入れたときに、私がしたいことはあり、基本的に
Sub Load_Balancing()
Dim i as integer, j as integer, k as integer
Dim Vacay as string, Vacaypercent as string
Dim Person as Long, Person1 As long, Person1Int as Long, LastRowVacay as Long
Person = Application.WorksheetFunction.CountIf(Range("B:B"), "=Person1")
For i = 3 To 18
Vacay = Application.InputBox("Enter Name", "Enter full name",Type:=2)
If Len(Vacay) = 0 Then Exit For
ws.Cells(i, 6).Value = Vacay
Vacay = ""
Vacaypercent = Application.InputBox("Enter percent reduction",
"Enter % reduction", Type:=2)
ws.Cells(i, 7).Value = Vacaypercent
Vacaypercent = ""
Next i
LastRowVacay = ws.Cells(Rows.Count, "F").End(xlUp).Row
For j = 3 To LastRowVacay
Cells(j, 7).Value = (Cells(j, 7).Value * 0.01)
Next j
j = 0
For j = 3 To LastRowVacay
On Error Resume Next
If Cells(j, 6).Value = "Person1 Name" Then
Person1Int = WorksheetFunction.Round(Person1 * Cells(j, 7).Value)
k = 0
For k = 3 To LastRowAssignments
'This is where the relevant code should go
Else: Exit For
End If
Next j
End Sub
データは次のようになりますそのマクロは、割り当てられた合計の割合をその人の名前から削除し、その場所に空白のセルを残す必要があります。たとえば、Person1はサンプルデータに4回表示されます。ときに、ユーザーがPERSON1内の型と50、PERSON1の最初の2つのインスタンスはこれを残して、リストから削除する必要があります。
Data | Name
--------------
1234 |
3456 |
8768 | Person2
0878 | Person3
4132 | Person5
0986 | Person1
0182 | Person5
0197 | Person4
4501 | Person2
4132 | Person2
8126 | Person4
0172 | Person4
0911 | Person4
0751 | Person3
6681 | Person1
8819 | Person2
しかし、私はこれについて移動する方法がわからないです。私はカウンターを効果的に使う必要があることを知っていますが、どのような形でそれを取るべきかを理解することはできません。何かアドバイスをいただければ幸いです!
非常にうまくいった、ありがとう!実際には複数の値をカラムから削除する必要があり、完全に機能していたため、少し修正しました。 – NLourme
それを聞いてうれしい!あなたのプロジェクトの残りの部分と幸運! –