|
在 J 列扫码信息数据自动分列,日期,时间,动生成加扫码代码可以实现。
全部代码如下:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim str As String
Dim x As Integer
Dim Rng As Range
Set Rng = Range("J5:J" & Range("J1048576").End(xlUp).Row)
For Each cell In Rng
str = Replace(Replace(Replace(cell.Text, "---", "-"), "--", "-"), " ", "")
c = 11
r = cell.Row
For Each e In Split(str, "*")
Cells(r, c) = e
c = c + 1
Next
Next
'Update 20140722
Dim WorkRng As Range
Dim Rng As Range
Dim xOffsetColumn As Integer
Set WorkRng = Intersect(Application.ActiveSheet.Range("J:J"), Target)
xOffsetColumn = -9
If Not WorkRng Is Nothing Then
Application.EnableEvents = False
For Each Rng In WorkRng
If Not VBA.IsEmpty(Rng.Value) Then
Rng.Offset(0, xOffsetColumn).Value = Date
Rng.Offset(0, xOffsetColumn).NumberFormat = "dd-mm-yyyy"
Else
Rng.Offset(0, xOffsetColumn).ClearContents
End If
Next
Application.EnableEvents = True
End If
Dim i As Integer
Set WorkRng = Intersect(Application.ActiveSheet.Range("J:J"), Target)
xOffsetColumn = -8
If Not WorkRng Is Nothing Then
Application.EnableEvents = False
For Each Rng In WorkRng
If Not VBA.IsEmpty(Rng.Value) Then
Rng.Offset(0, xOffsetColumn).Value = Now
Rng.Offset(0, xOffsetColumn).NumberFormat = "hh:mm:ss"
Else
Rng.Offset(0, xOffsetColumn).ClearContents
End If
Next
Application.EnableEvents = True
End If
Dim i
For i = 1 To [a65536].End(3).Row
Range("b" & i) = Format(Range("a" & i), "ww")
Next
' 检查变更的单元格是否为A列
If Not Intersect(Target, Range("N:N")) Is Nothing Then
' 计算A列的和,并将结果显示在B1单元格
Range("R5").Value = Application.WorksheetFunction.Sum(Range("N:N"))
End If
If Not Intersect(Target, Range("G:G")) Is Nothing Then
' 计算A列的和,并将结果显示在B1单元格
Range("S5").Value = Application.WorksheetFunction.Sum(Range("G:G"))
End If
If (Target.Column = 7 Or Target.Column = 14) And Target.Row > 4 Then
r = Target.Row
Range("h" & r) = Range("g" & r) / Range("n" & r)
End If
End Sub
|
-
|