Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 31st, 2006, 10:30 PM
Registered User
 
Join Date: Jul 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Urgent Plea to all VBA Experts!!

Need urgent help on the following issue, where I have to come up with a very difficult macro (never written one!)

I have three excel sheets:
Sheet “Inputs”, Sheet “Numbers”, and Sheet “Calculate”

What is supposed to happen:
-Sheet Numbers contains an array of numbers, extending from columns B to m & from rows 2 to k + 1, whereby m & k are specified in sheet "Inputs" (I have this array already & the Macro generating this array in sheet "Numbers"-see bottom of this post)
-Sheet “Calculate” is supposed to transform each value of the array in Sheet Numbers through the following formula:
‘=-1/h*LN(1-ValueFromSheet”Numbers),
whereby the respective value h is also specified in SheetInputs, row 21 (see below)
-Sheet Inputs specifies the exact extend of the array in Sheet”Numbers” by specifying the m & the k:
Cell B2 in sheet “Inputs” contains a column label (e.g. W) which specifies the m
Cell B3 in sheet “Inputs” contains a number which specifies the k (i.e. the row number of the array in Sheet “Calculate”)
>For instance, if cell B2 in Sheet “Inputs” contains the letter ‘W’ and cell B3 in sheet "Inputs" contains the number 220, then the array of numbers in sheet “Calculate” will extend from B2 to W221 (because the row number is defined as k+1)
-Moreover, row 21 in sheet “Inputs” contains (from column B to FY) the values for h which are supposed to be used in the formulas in the corresponding columns in sheet “Calculate”
-As mentioned above, sheet “Calculate” is supposed to transform each value of sheet “Numbers” according to the formula
=(-1/h*LN(1-ValueFromSheetNumbers)), whereby the “h” comes from
row 21 in sheet “Inputs” (the column is supposed to be the same as the column of the cell in Sheet Calculate that is being calculated, i.e. if the cell to be calculated in sheet “Calculate” is cell K44, then the value fo h to be used is in cell K21 in sheet “Input)
>For instance, cell J52 in sheet “Calculate” shall contain the results of the formula: (-1/Inputs!J$21)*LN(1-Numbers!J52)
>Likewise, cell Y119 shall contain the formula
=(-1/Inputs!Y$21)*LN(1-Numbers!Y119)

Note:
- the cell reference to be used from sheet "Numbers" is the very same as the cell to be calculated in sheet "Calculate" (e.g. Y119)
- the cell reference in sheet "Inputs" containing the relevant value for the h has the same column label (e.g. Y) as the cell to be calculated in sheet "Calculate" (i.e. Y), whereas the row # is always 21

-at the end of the Macro, sheet “Calculate” is supposed to contain an array of the same extend as that in sheet Numbers (i.e. from B2 to cell(m,i+1), whereby each of the values in sheet “Numbers” has been transformed according to the abovementioned formula


BTW: the numbers in sheet “Numbers” are generated using the following Macro

Sub Random()
Sheets("Inputs").Calculate
m = Sheets("Inputs").Range("B2").Value
k = Range("Inputs!B3").Value
For i = 2 To k + 1
Range("B" & i & ":" & m & i).FormulaArray = "=TRANSPOSE(RandBM(Inputs!R2C2))"
Next i

End Sub


Many thanx to everyone who takes the time to reply!!

Burki

 
Old August 1st, 2006, 10:56 AM
Registered User
 
Join Date: Jul 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Could this be a solution?


Sub Calculate()

Dim wsInputs As Worksheet
Dim wsCalculate As Worksheet
Dim wsNumbers As Worksheet
Dim Col As Integer

Dim i As Long
Dim j As Integer

Set wsInputs = ThisWorkbook.Worksheets("Inputs")
Set wsCalculate = ThisWorkbook.Worksheets("Calculate")
Set wsNumbers = ThisWorkbook.Worksheets("Numbers")

' get the col position starting from letter

Col = CorrCol(wsInputs.Cells(2, 2))
MsgBox CorrCol(wsInputs.Cells(2, 2))

For i = 2 To wsInputs.Cells(3, 2) + 1
    For j = 2 To Col
        wsCalculate.Cells(i, j) = _
            (-1 / wsInputs.Cells(21, j)) * Log(1 - wsNumbers.Cells(i, j))
    Next j
Next i

Set wsInputs = Nothing
Set wsCalculate = Nothing
Set wsNumbers = Nothing

End Sub


Function CorrCol(Letter As String) As Integer
'Calculate the corresponding column starting from a letter
' (or group of letters)
Dim i As Integer
Dim j As Integer
Dim k As Integer

CorrCol = 0
i = Len(Letter)
If i > 2 Then Exit Function
k = 0
For j = 1 To i
    k = k * 26 + (Asc(Mid$(Letter, j, 1)) - 64)
    If k < 1 Then Exit Function
Next j

If k <= 256 Then CorrCol = k
End Function

Ciao

Mario





Similar Threads
Thread Thread Starter Forum Replies Last Post
Another Plea for Thearon PaulBerry BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 1 January 26th, 2008 07:59 AM
Chapter 8 - A plea to Thearon Willis Petrina BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 2 July 10th, 2007 03:51 AM
Urgent: Finding meanings of a word using VBA SMI Word VBA 2 March 26th, 2007 08:13 AM
urgent VBA code wanted helmekki Excel VBA 2 May 12th, 2004 03:57 AM
How do I.....? One for the Experts!? ziwez0 Access VBA 13 October 20th, 2003 05:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.