Home > Software engineering >  To get the number of changes in detail
To get the number of changes in detail

Time:10-17

Type CHANGEDETAIL
StrChangeDetailNo As String 'change a number of details to
StrChangeDetail details As String 'change
StrChangeNo (large) As String 'change our
StrTemp As String
End Type

Type CNANGEPOINT
StrChangePoint () As CHANGEDETAIL
StrTemp As String
End Type

Dim myChangePoint As CNANGEPOINT

Sub Macro2 ()
Dim rngTest As Range

The Set rngTest=Range (" F5: F100 ")
Call getContext (rngTest)
'for each big change point, continue down to each small change point,
'with this count

Erase myChangePoint. StrChangePoint ()
End Sub

The Function getContext (rngTst As Range)
Dim iRngColumn As Integer
Dim iRngStartRow As Integer
Dim iRngEndRow As Integer
Dim iCountPoint As Integer
Dim iCountDetail As Integer
Dim I, iCount As Integer
Dim iLength As Integer

IRngStartRow=rngTst. Row
IRngEndRow=iRngStartRow + rngTst. Rows. The Count - 1
IRngColumn=rngTst. Column

ICountPoint=0
ICountDetail=0
'For Each oCell rngTst In
For I=iRngStartRow To iRngEndRow
Whether you need a change 'statistical
'if the cells did not change the serial number, and there are no changes to the content, not as a change point
IRngColumn, If (Cells (I) the Text="" And Cells (I, iRngColumn). Offset (0, 1). The Text=" ") Then

The Else
'if the change serial number or change the content of it is not empty
'whether merge cells
If (Cells (I, iRngColumn). MergeCells) Then
'first of all, as a big change point meter, but need to record the next
the coordinates of the cellICountPoint=iCountPoint + 1
ReDim Preserve myChangePoint. StrChangePoint (1 To iCountPoint)
MyChangePoint. StrChangePoint (iCountPoint). StrChangeNo=Cells (I, iRngColumn). The Text
'to merge cells need to be plural cell content
For iCount=0 To GetMergeCellRow (Cells (I, iRngColumn)) - 1
MyChangePoint. StrChangePoint (iCountPoint). StrChangeDetail=myChangePoint. StrChangePoint (iCountPoint). StrChangeDetail & amp; VbLf & amp; Cells (I + iCount, iRngColumn). Offset (0, 1). The Text
Next iCount
'the Debug. Print myChangePoint. StrChangePoint (iCountPoint). StrChangeDetail
MyChangePoint. StrChangePoint (iCountPoint). StrChangeDetailNo=GetChangeDetail (myChangePoint. StrChangePoint (iCountPoint). StrChangeDetail)
I=I + GetMergeCellRow (Cells (I, iRngColumn)) - 1 'need to skip the merged cell number of columns, because recycling an I will increase 1, so here to buckle a
The Else
'not merged cell, first as a big change point count
ICountPoint=iCountPoint + 1
ReDim Preserve myChangePoint. StrChangePoint (1 To iCountPoint)
MyChangePoint. StrChangePoint (iCountPoint). StrChangeNo=Cells (I, iRngColumn). The Text
MyChangePoint. StrChangePoint (iCountPoint). StrChangeDetail=Cells (I, iRngColumn). Offset (0, 1). The Text
'the Debug. Print myChangePoint. StrChangePoint (iCountPoint). StrChangeDetail
MyChangePoint. StrChangePoint (iCountPoint). StrChangeDetailNo=GetChangeDetail (myChangePoint. StrChangePoint (iCountPoint). StrChangeDetail)
End the If
End the If
Next I
End the Function

The Function GetMergeCellRow (oCell As Range) As an Integer
Dim As Integer I
Dim TempCell As Range
Dim TempCell2 As Range

I=0
The Set TempCell=oCell
The Set TempCell2=TempCell. Offset (1, 0)
GetMergeCellRow=TempCell2. Row - TempCell. Row 'return to merge the cell's Row number

End the Function

'return to change the detail of the number change
The Function GetChangeDetail (ByRef strDetail As String) As an Integer
Dim arrDetail () As String
Dim As Integer I
Dim sTemp As String
Dim iCount the As Integer

ICount=0
'change details according to the line segmentation
ArrDetail=Split (strDetail vbLf)
'for the partition of each line, to judge whether there is a number mark in the beginning, if belong to the number, the change point 1
For I=0 To UBound (arrDetail)
STemp=arrDetail (I)
STemp=LTrim (sTemp)
STemp=RTrim (sTemp)
If sTemp Like "[1-9] * [.,] * 'Then' begin with several Numbers (such as 000,11,99999 etc.), followed by". "or," ", followed by any character,
ICount=iCount + 1
The Else

End the If
Next I

GetChangeDetail=iCount
End Function

CodePudding user response:

Put a piece of code, to be the problem?
  •  Tags:  
  • VBA
  • Related