LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default How do I pass a value in a range command

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass Command Button info J Streger Excel Programming 3 February 5th 10 08:51 PM
Pass Defined Name to a Command Button Connie Excel Programming 3 October 10th 06 07:45 AM
Pass a cell in sheet to macro or command button Connie Excel Programming 2 October 8th 06 04:54 PM
How to: Pass Command Line Parameter ??? Webtest Excel Worksheet Functions 0 October 24th 05 05:27 PM
Command and pass value to Acces from Excel Looko Excel Programming 0 May 31st 04 01:23 AM


All times are GMT +1. The time now is 07:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"