Java教程

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

这篇关于vba for yingying的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!