|
楼主 |
发表于 2015-12-8 19:09
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub Test_LLc2()
- Dim i%, j%, k% '定义几个for循环用的变量
- Dim Lr% '定义本表格的行边界
- Dim Sh As Worksheet '定义工作
- Set Sh = Sheet4 '指定工作表
- Lr = Sh.Range("A65536").End(xlUp).Row '指定行边界行数
- Dim Arr '定义一个variant变量
- Dim LLC% '定义一个BOM层次码变量
- LLC = 1 '初始化为1
- 'Arr = sh.Range("A2:C" & Lr) '将指定区域赋给Arr
- i = 1
- '开始循环判断
- With Sh
- Do
- i = i + 1
- If .Cells(i, 4) = 1 Then
- If .Cells(i, 11) <> "X" Then
- .Cells(i, 12) = "Y"
- Else
- i = Dg(i, LLC + 1)
-
- End If
- End If
- Loop Until i = Lr
- '.Cells(2, 1).Resize(UBound(Arr, 1), UBound(Arr, 2)) = Arr
- End With
- Set Sh = Nothing '结束
-
- End Sub
- Function Dg(ByVal i_Row As Integer, ByVal S_Llc As Integer)
-
- Dim Sh As Worksheet
- Set Sh = Sheet4
-
- With Sh
- Do
- i_Row = i_Row + 1
- If .Cells(i_Row, 4) = S_Llc Then
- If .Cells(i_Row, 11) <> "X" Then
- .Cells(i_Row, 12) = "Y"
- 'Dg = i_Row
- Else
- i_Row = Dg(i_Row, S_Llc + 1)
- End If
- Else
- '
-
- End If
-
-
- Loop Until .Cells(i_Row, 4) = S_Llc - 1
-
- End With
- Dg = i_Row - 1
- End Function
复制代码 |
|