ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 471|回复: 7

[求助] 求助,求助。这个完成后的表格按条件分配怎么完成?

[复制链接]

TA的精华主题

TA的得分主题

发表于 2023-3-23 13:49 | 显示全部楼层 |阅读模式
1、“完成后表格” 内  “总表” 数据需要分配至  分表从“A-(一”、“A-(二”......“B-(二十一”、“B-(二十二”。


2、分配条件为:“总表” 内客户号列   +    轮规格A 列  对比条件在 “集成配置及排产流程 2023.03.10” 表的“填表” 内 客户号列 + 轮规格A 列

3、“填表” 内机加组别的4列参照 “集成配置及排产流程” 内的G列

4、分配时“总表”内分配至分表后数量不超过“集成配置及排产流程” 的I列产能。

条件参照表格.rar

1.33 MB, 下载次数: 3

完成后表格.rar

544.95 KB, 下载次数: 2

TA的精华主题

TA的得分主题

发表于 2023-3-23 14:07 | 显示全部楼层
体力活。。。。。

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-3-23 14:10 | 显示全部楼层

  这个体力活啊?很麻烦吗?

TA的精华主题

TA的得分主题

发表于 2023-3-23 15:52 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
你这个,建议你找付费的做了。
如果免费,一般人不太愿意花过多的时间去写代码。

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-3-24 09:00 | 显示全部楼层
ykcbf1100 发表于 2023-3-23 15:52
你这个,建议你找付费的做了。
如果免费,一般人不太愿意花过多的时间去写代码。

这个一般需要多少钱啊?有收费标准吗?

TA的精华主题

TA的得分主题

发表于 2023-3-24 09:40 | 显示全部楼层
cxxyzjsxy 发表于 2023-3-24 09:00
这个一般需要多少钱啊?有收费标准吗?

这个不知道啊。
论坛中,你出个50元、100元先试试吧。

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-3-24 10:35 | 显示全部楼层

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-3-24 11:04 | 显示全部楼层
ykcbf1100 发表于 2023-3-23 15:52
你这个,建议你找付费的做了。
如果免费,一般人不太愿意花过多的时间去写代码。

Sub AllocateData()

    ' Define the worksheet objects for the total and fill tables
    Dim totalTable As Worksheet
    Dim fillTable As Worksheet
    Dim integratedTable As Worksheet
   
    Set totalTable = ThisWorkbook.Worksheets("完成后表格").Range("总表").Worksheet
    Set fillTable = ThisWorkbook.Worksheets("集成配置及排产流程 2023.03.10").Range("填表").Worksheet
    Set integratedTable = ThisWorkbook.Worksheets("集成配置及排产流程 2023.03.10").Range("G:I").Worksheet
   
    ' Define the data ranges for the total and fill tables
    Dim totalData As Range
    Dim fillData As Range
   
    Set totalData = totalTable.Range("A1").CurrentRegion
    Set fillData = fillTable.Range("A1").CurrentRegion
   
    ' Loop through each row in the total data range
    For i = 2 To totalData.Rows.Count
   
        ' Find the matching row in the fill data range
        Set fillRow = fillData.Rows.Find(What:=totalData(i, 1).Value & totalData(i, 6).Value, _
            LookIn:=xlValues, LookAt:=xlWhole)
        
        If Not fillRow Is Nothing Then
        
            ' Determine the corresponding integrated table row and column
            Dim rowHeader As String, columnHeader As String
            
            rowHeader = fillData(fillRow.Row, 4).Value
            columnHeader = fillData(fillRow.Row, 1).Value & fillData(fillRow.Row, 2).Value
            
            Set intRange = integratedTable.Range("A1").CurrentRegion
            
            For Each cell In intRange.Cells
                If cell.Value = columnHeader And cell.Row = 1 Then
                    colIndex = cell.Column
                    Exit For
                ElseIf cell.Value Like rowHeader & "*" And cell.Column = 1 Then
                    rowIndex = cell.Row
                    Exit For
                End If
            Next cell
            
            ' Determine the integrated table capacity
            Dim capacity As Double
            
            If Not rowIndex = 0 And Not colIndex = 0 Then
                capacity = integratedTable.Cells(rowIndex, colIndex + 2).Value
            End If
            ' Calculate the quantity to be allocated
            Dim quantity As Double, allocatedQty As Double
            
            quantity = totalData(i, 5).Value
            allocatedQty = WorksheetFunction.Min(quantity, capacity)
            
            ' Allocate the data to the corresponding table
            If Not allocatedQty = 0 Then
                ' Determine the corresponding table letter and row
                tableHeader = fillData(fillRow.Row, 2).Value & "-"
                tableRow = fillData(fillRow.Row, 5).Value
               
                ' Find the matching table sheet
                For Each ws In ThisWorkbook.Worksheets
                    If ws.Name Like "分表 " & tableHeader & "*" Then
                        Set tableRange = ws.Range("A1").CurrentRegion
                        Exit For
                    End If
                Next ws
               
                If Not tableRange Is Nothing Then
                    ' Determine the column index in the table range
                    For Each cell In tableRange.Rows(1).Cells
                        If cell.Value = tableHeader & tableRow Then
                            colIndex = cell.Column
                            Exit For
                        End If
                    Next cell
                    
                    ' Find the next available row in the table range and allocate the quantity
                    For j = 2 To tableRange.Rows.Count
                        If tableRange(j, 1).Value = "" Then
                            tableRange(j, colIndex).Value = allocatedQty
                            Exit For
                        End If
                    Next j
                End If
            End If
        End If
    Next i
End Sub

这个需要么修改呢。这个可以用吗?
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-9-29 16:18 , Processed in 0.036826 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表