其他分享
首页 > 其他分享> > vba for yingying

vba for yingying

作者:互联网

Dim strNameCase As String
Dim nInputDataStartRow As Integer
Dim nOutputDataTitleRow As Integer
Dim nInputColFunc As Integer
Dim nInputColSubFunc As Integer
Dim nInputColMember As Integer
Dim nInputColValue As Integer
Dim nInputColMemberList As Integer
Dim nInputRowMemberList As Integer
Dim nOUtputdatatitlecol As Integer

Dim lastRow As Integer
Dim lastCol As Integer

Private Sub Init()

'clear sheet bb
'pass

'these will init with find keyword
strNameCase = “案件名”
nInputDataStartRow = 3
nInputColFunc = 2
nInputColSubFunc = 3
nInputColMember = 4
nInputColValue = 5
nInputColMemberList = 3
nInputRowMemberList = 2
nOutputDataTitleRow = 2
nOUtputdatatitlecol = 2
lastRow = 3
lastCol = 3

Sheets(“BB”).Range(“B2”).Value = strNameCase

'init member list
Dim coltmp As Integer
coltmp = nInputColMemberList

Do While Sheets(“Control”).Cells(nInputRowMemberList, coltmp).Value <> “”
Sheets(“BB”).Cells(nOutputDataTitleRow, lastCol).Value = Sheets(“Control”).Cells(nInputRowMemberList, coltmp).Value
lastCol = lastCol + 1
coltmp = coltmp + 1
Loop

End Sub

Function GetOutputRowCase(ByVal strcase As String) As Integer

Dim row As Integer
Dim found As Boolean
found = False
row = nOutputDataTitleRow

Do While row <= lastRow
If Sheets(“BB”).Cells(row, nOUtputdatatitlecol).Value = strcase Then
GetOutputRowCase = row
found = True
End If
row = row + 1
Loop

If Not found Then
GetOutputRowCase = -1
End If

End Function

Function GetOutputColMember(ByVal strMember As String) As Integer

Dim col As Integer
Dim found As Boolean
found = False
col = nOUtputdatatitlecol

Do While col <= lastCol
If Sheets(“BB”).Cells(nOutputDataTitleRow, col).Value = strMember Then
GetOutputColMember = col
found = True
End If
col = col + 1
Loop

If Not found Then
GetOutputColMember = -1
End If

End Function

Private Sub CommandButton1_Click()

Init

'start copy
Dim row As Integer
row = nInputDataStartRow

Dim nOutputRowCase As Integer
Dim nOutputColMember As Integer
Dim strInputCase As String
Dim strInputSubCase As String
Dim strInputMember As String
Dim dInputValue As Double
Dim strcase As String

Do While Sheets(“AA”).Cells(row, nInputColValue).Value <> “”

strInputCase = Sheets("AA").Cells(row, nInputColFunc).Value
strInputSubCase = Sheets("AA").Cells(row, nInputColSubFunc).Value
strInputMember = Sheets("AA").Cells(row, nInputColMember).Value
dInputValue = Sheets("AA").Cells(row, nInputColValue).Value
  
If strInputSubCase <> "" Then
  strcase = strInputSubCase
ElseIf strInputCase <> "" Then
  strcase = strInputCase
Else
  'error
End If

'Get write row
nOutputRowCase = GetOutputRowCase(strcase)
If nOutputRowCase = -1 Then
  nOutputRowCase = lastRow
  lastRow = lastRow + 1
  Sheets("BB").Cells(nOutputRowCase, nOUtputdatatitlecol).Value = strcase
End If

'Get write col
nOutputColMember = GetOutputColMember(strInputMember)
If nOutputColMember = -1 Then
  nOutputColMember = lastCol
  lastCol = lastCol + 1
  Sheets("BB").Cells(nOutputDataTitleRow, nOutputColMember).Value = strInputMember
End If

'Set Value
Sheets("BB").Cells(nOutputRowCase, nOutputColMember).Value = dInputValue

row = row + 1

Loop

End Sub

标签:Dim,vba,Cells,yingying,Value,Sheets,Integer,row
来源: https://blog.csdn.net/weixin_47485475/article/details/120573858