ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

vba for yingying

2021-09-30 23:59:18  阅读:211  来源: 互联网

标签:Dim vba Cells yingying Value Sheets Integer row


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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有