Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have the following code to modify specific ranges in a number of exel
files. Is it possible to set a variable in the code to pass the range name though to the Range command so I dont have to repeat the process, but only check for a given range name and update that field with the value? i.e. i want to change [Range("loan_margin").Value = loanmargin] "loan_margin" to refer to a variable that contains the range name to update. thanks george Sub modcollat() ' ============================== ' Define Variables ' ============================== Dim poolfile As String Dim collatfile As String Dim Theresponse As String Dim numcollat As Integer Dim Collatloop As Integer Dim collatincluded As Integer Dim drawamount As String Dim poolamount As String Dim loanmargin As String Dim modrate As String Dim drawamountwrite As String Dim poolamountwrite As String Dim loanmarginwrite As String ' ============================== ' Initialize Variables ' ============================== poolfile = ActiveWorkbook.Name drawamountwrite = Range("draw_amount_write").Value poolamountwrite = Range("pool_amount_write").Value loanmarginwrite = Range("loan_margin_write").Value modrate = Range("mod_rate").Value drawamount = Range("i_draw_amount").Value poolamount = Range("i_pool_amount_to_date").Value loanmargin = Range("i_loan_margin").Value collatincluded = 0 Application.ScreenUpdating = False numcollat = WorksheetFunction.Max(Range("array_collatfilenum") .Value) ' ============================== ' Loop through each collat file ' ============================== For Collatloop = 1 To numcollat If Range("array_collatfileinclude").Cells(Collatloop) = 1 Then '============================ 'Open the collat file '============================ Workbooks.Open Filename:=Range("array_collatfilename").Cells(Coll atloop) collatfile = ActiveWorkbook.Name collatincluded = collatincluded + 1 '======================================== 'Go to Collat File & Copy Data '======================================== Windows(collatfile).Activate '**************** '* This pastes the current draw amount and the pool amount to date from the pool file '* to each collateral file so the IC Memo tables show the correct % '************** If drawamountwrite = "Yes" Then Range("draw_amount").Value = drawamount End If If poolamountwrite = "Yes" Then Range("pool_amount_to_date").Value = poolamount End If If loanmarginwrite = "Yes" Then Range("loan_margin").Value = loanmargin End If ' ================================ ' go to collateral file and close ' ================================ Range("A1").Copy ' JUST TO CLEAR CLIPBOARD Windows(collatfile).Activate ActiveWorkbook.Close savechanges:=True End If Next Collatloop MsgBox ("IC Memo from " + WorksheetFunction.Text(collatincluded, "0") + " collateral updated ") End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Pass Command Button info | Excel Programming | |||
Pass Defined Name to a Command Button | Excel Programming | |||
Pass a cell in sheet to macro or command button | Excel Programming | |||
How to: Pass Command Line Parameter ??? | Excel Worksheet Functions | |||
Command and pass value to Acces from Excel | Excel Programming |