|
老窖兄:
第一次看你的帖,被你这种无私奉献的精神所感动!-----敬礼!!!
你的这个课题实用性很强,但是由于初学VBA还是不怎么看的懂你的代码,
可否讲解一下开单工作表的代码?不胜感激--坐着板凳求学中。。。。。。
Range("I3").ClearContents
Range("C5:I5").ClearContents
填充列表框
设置格式 Range("B6:I60")
设置边框 Range("B6:I60")
Range("E3").Select
Me.Protect
Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Column <= 2 Then Exit Sub
If Target.Offset(, -1) <> "组立品番" Then Exit Sub
On Error Resume Next
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.Calculation = xlManual
Me.Unprotect
Dim i&
设置格式 Range("B" & Target.Row + 1 & ":I60")
设置边框 Range("B" & Target.Row + 1 & ":I60")
i = 1
If 填充子项数据(Target, i) Then
Do Until Len(Target.Offset(i)) = 0
Target.Offset(i, -1) = i
Target.Offset(i, 3).Formula = "=D$" & Target.Row & "*E" & Target.Offset(i).Row
Target.Offset(i, 4).Formula = "=F" & Target.Offset(i).Row
Target.Offset(i, 5).Formula = "=F" & Target.Offset(i).Row
i = i + 1
Loop
Target.Offset(, -1).Resize(1, 8).Copy Target.Offset(i + 1, -1)
Target.Offset(i + 1).Resize(1, 2).ClearContents
With Target.Offset(1, 4).Resize(i - 1, 3)
.Locked = False
.Interior.Color = Target.Interior.Color
End With
End If
Me.Protect
Application.Calculation = xlAutomatic
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Target.Offset(, -1) = "组立品番" Then
With Me.ComboBox1
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width
.Height = Target.Height
.Visible = True
End With
Else
Me.ComboBox1.Visible = False
End If
End Sub
Private Sub ComboBox1_Click()
With Me.ComboBox1
.TopLeftCell.Value = .Value
.TopLeftCell.Offset(0, 1).Activate
End With
End Sub
Private Sub 填充列表框()
Dim cnn As ADODB.Connection, rs As ADODB.Recordset
Dim i%, Sql$, strL$, firstAddr$
On Error Resume Next
Me.ComboBox1.Clear
Set cnn = New ADODB.Connection
Set rs = New ADODB.Recordset
cnn.Open "provider=microsoft.jet.oledb.4.0;extended properties='excel 8.0;hdr=yes;';Data Source=" & ThisWorkbook.FullName
Sql = "select distinct [成品料号] from [ok改基础BOM_子品原料需求结存$B:G]"
rs.Open Sql, cnn, adOpenKeyset, adLockOptimistic
For i = 1 To rs.RecordCount
Me.ComboBox1.AddItem rs!成品料号
rs.MoveNext
Next i
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
End Sub
|
|