Sub ClientRatios()
'DataSet is in range A:A
'Make the ratios of the Clients Add up to 10
'You can have a maximum of 10 clients
Dim Nextempty As Range
Dim j As Long
Dim i As Long
'Repeat the following idea for each client and you should get what you're looking for
'+++Client1+++
'=================================
i = Range("Clinet1_Ratio")
ClientName = Range("Clinet1_Name")
'=================================
Total = Application.WorksheetFunction.CountIf(Range("A:A"), ClientName)
Do While Total < 0
j = i
c = 2
Do While j > 0
If j > Total Then j = Total
Nextempty = Cells(Cells.Rows.Count, Columns(c)).End(xlUp).Row + 1
Nextempty = ClientName
j = j - 1
Loop
c = c + 1
Total = Total - i
Loop
'+++Client2+++
'Do the same for all 10 clients
End Sub
2条答案
按热度按时间tp5buhyn1#
希望这有帮助。这将把你的块放在列中,彼此相邻。我没有测试这个,但希望这个想法会让你有所收获。
q0qdq0h22#
我建议您使用Microsoft脚本运行库(Windows附带)中的
Dictionary
对象。链接here和here1.将源数据读入一个
dictionary
,这样就可以存储客户机名称和每个名称的计数。1.循环遍历比率单元格,每次将客户端名称写入字典,然后减少计数。如果某个名称的计数= 0,则不写出该名称。
1.当dictionary中的所有客户端名称计数= 0时,退出循环,您就完成了。