调整公共最后一行值时多次调用过程

时间:2016-06-13 17:37:15

标签: excel vba excel-vba call

我在将工作表作为参数

传递时调用过程RB_Build
RB_Build "Main"
RB_Build "ETF"
RB_Build "MAV"

以下是在被调用过程中执行的一些代码

Sheets("Request Builder").Select
sourceCol = 1   'column A has a value of 1
   rowCount = Cells(Rows.Count, sourceCol).End(xlUp).Row
       ' rowCountv2 = Range("A" & Rows.Count).End(xlUp).Offset(1).Row
Range("a1:a" & NewRow) = NewList
RB_LastRow = Range("a65000").End(xlUp).Row

如何调整行Range("a1:a" & NewRow) = NewList以找到最后一行,请注意每次调用上述程序后,最后一行会增加,因为我在每次调用时附加数据。

首先,我有Dim RB_LastRow as Public并计划在每个被调用的过程之后以某种方式递增RB_LastRow,但我不知道如何适当增加,也不知道如何修改范围行以包含新的最后一个行值。

编辑:完整代码

Sub RB_Build(ws_string As String)

'Sheets("Request Builder").Range("a2:zz65000").ClearContents

Sheets(ws_string).Activate
RB_LastRow = Range("b65000").End(xlUp).Row

aRB_Row = 0
NewRow = 0


        cName = "Fund ID"
        cA = ActiveSheet.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
        cName = "BBH ID"
        cB = ActiveSheet.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
'        cName = "Description"
'        cC = ActiveSheet.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
        cName = "Security Type"
        cD = ActiveSheet.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
'        cName = "Currency"
'        cE = ActiveSheet.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
        cName = "Price Date"
        cF = ActiveSheet.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
        cName = "Current Price"
        cG = ActiveSheet.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
        cName = "Prior Price"
        cH = ActiveSheet.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
'        cName = "Change Price (%)"
'        cI = ActiveSheet.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
        cName = "BPS Impact"
        cJ = ActiveSheet.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
        cName = "Source"
        cK = ActiveSheet.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
        cName = "Source"
'        cL = activesheet.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
'        cName = "SSIMS - Comment"
'        cM = activesheet.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
'        cName = ""
'        cN = activesheet.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
'        cName = ""
'        cO = activesheet.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
'        cName = "Current Fx Rate"
'        cP = activesheet.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column
'        cName = "Prior Fx Rate"
'        cQ = activesheet.Rows.Find(What:=UCase(cName), LookAt:=xlWhole, SearchDirection:=xlNext).Column

                For r = 2 To RB_LastRow
                        aRB_Row = aRB_Row + 1
                            aRB(aRB_Row, 1) = CStr(Cells(r, cA)) 'Fund ID ' added string value method
                            aRB(aRB_Row, 2) = Cells(r, cB)            'Client CUSIP
'                            aRB(aRB_Row, 3) = Cells(r, cC)            'Description
                            aRB(aRB_Row, 4) = Cells(r, cD)            'Security Type
                            'aRB(aRB_Row, 5) = Cells(r, cE)            'Currency
                            aRB(aRB_Row, 6) = Cells(r, cF)            'Price Date
                            aRB(aRB_Row, 7) = Cells(r, cG).Value      'Current Price
                            'Debug.Print aRB_Row
                            aRB(aRB_Row, 8) = Cells(r, cH).Value      'Prior Price
                            'aRB(aRB_Row, 9) = Cells(r, cI)            'Change Price (%)
                            aRB(aRB_Row, 10) = Cells(r, cJ)           'BPS Impact
                            aRB(aRB_Row, 11) = Cells(r, cK)           'Source
                            'aRB(aRB_Row, 12) = Cells(r, cL)           'SSIMS - Comment

                Next r

Set RB_List = CreateObject("scripting.dictionary")
RB_List.RemoveAll
Set RB_List = Nothing

Set RB_List = CreateObject("scripting.dictionary")
        NewRow = 1
For r = 1 To aRB_Row



'    If aRB(r, 7) = MyDate Then ' only check CD action
'        If RB_List.Exists(aRB(r, 2)) Then
'        Else
        'If Len(aRB(r, 2)) = 7 Or Len(aRB(r, 2)) = 9 Or Len(aRB(r, 2)) = 12 Then 'skip internal id
        'NewRow = NewRow + 1

'        If UCase(Left(aRB(r, 2), 3)) <> "317" Then
If aRB(r, 11) = "Idcbond" Or aRB(r, 11) = "Reuters" Or aRB(r, 11) = "Bbfut" Or aRB(r, 11) = "" Then


            If Len(aRB(r, 2)) = 7 Then
                NewList(NewRow, 1) = aRB(r, 2) & "|SEDOL"
                NewRow = NewRow + 1
            ElseIf Len(aRB(r, 2)) = 9 And Not UCase(Left(aRB(r, 2), 2)) = "SW" Then 'UCase(Left(aRB(r, 2), 2)) = "SW"
                NewList(NewRow, 1) = aRB(r, 2) & "|CUSIP"
                NewRow = NewRow + 1
            ElseIf Len(aRB(r, 2)) = 12 Then
                NewList(NewRow, 1) = aRB(r, 2) & "|ISIN"
                NewRow = NewRow + 1
            End If


        Else
            End If

'            With RB_List
'                .CompareMode = vbTextCompare
'                .Add aRB(r, 2), r
'            End With
        'End If
'       End If
'     End If
Next r


Sheets("Request Builder").Select

sourceCol = 1   'column A has a value of 1
With ActiveSheet
    rowCount = .Cells(.Rows.Count, sourceCol).End(xlUp).Row
    ' rowCountv2 = Range("A" & Rows.Count).End(xlUp).Offset(1).Row
    .Range("a1:a" & NewRow) = NewList
    RB_LastRow = .Range("a65000").End(xlUp).Row
End With

'sourceCol = 1   'column A has a value of 1
'   rowCount = Cells(Rows.Count, sourceCol).End(xlUp).Row
'       ' rowCountv2 = Range("A" & Rows.Count).End(xlUp).Offset(1).Row
'Range("a1:a" & NewRow) = NewList
'RB_LastRow = Range("a65000").End(xlUp).Row

Sheets("Macro").Activate

End Sub

0 个答案:

没有答案