+ Reply to Thread
Results 1 to 9 of 9

Attempting to create a macro that will use the model to calculate values for a data table.

  1. #1
    Registered User
    Join Date
    12-09-2019
    Location
    Antarctica
    MS-Off Ver
    2016
    Posts
    9

    Attempting to create a macro that will use the model to calculate values for a data table.

    I have a model that calculates Lease NERs (Net Effective Rent) for potential new leases. I am attempting to write a code that will plug in values from a data table (Sheet3) to the input tab (sheet1), calculate, then paste resulting values from the input page in the data table.

    So far my code looks as follows:

    BeginRow = 5
    Endrow = 6
    ChkCol = 2

    For RowCnt = BeginRow To Endrow
    If Cells(RowCnt, ChkCol).Value <> "" Then

    'New Lease
    Worksheets("Sheet1").Range("C28").Value = Worksheets("Sheet3").Cells(RowCnt, 13).Value
    Worksheets("Sheet1").Range("C29").Value = Worksheets("Sheet3").Cells(RowCnt, 16).Value
    Worksheets("Sheet1").Range("C34").Value = Worksheets("Sheet3").Cells(RowCnt, 19).Value
    Worksheets("Sheet1").Range("C36").Value = Worksheets("Sheet3").Cells(RowCnt, 25).Value
    Worksheets("Sheet1").Range("C30").Value = Worksheets("Sheet3").Cells(RowCnt, 31).Value
    Worksheets("Sheet1").Range("C27").Value = Worksheets("Sheet3").Cells(RowCnt, 34).Value
    Worksheets("Sheet1").Calculate
    Worksheets("Sheet3").Cells(RowCnt, 40).Value = Worksheets("Sheet1").Range("H28").Value
    'Lease Renewal
    Worksheets("Sheet1").Range("C28").Value = Worksheets("Sheet3").Cells(RowCnt, 13).Value
    Worksheets("Sheet1").Range("C29").Value = Worksheets("Sheet3").Cells(RowCnt, 16).Value
    Worksheets("Sheet1").Range("C34").Value = Worksheets("Sheet3").Cells(RowCnt, 22).Value
    Worksheets("Sheet1").Range("C36").Value = Worksheets("Sheet3").Cells(RowCnt, 28).Value
    Worksheets("Sheet1").Range("C30").Value = Worksheets("Sheet3").Cells(RowCnt, 31).Value
    Worksheets("Sheet1").Range("C27").Value = Worksheets("Sheet3").Cells(RowCnt, 37).Value
    Worksheets("Sheet1").Calculate
    Worksheets("Sheet3").Cells(RowCnt, 41).Value = Worksheets("Sheet1").Range("H28").Value

    End If
    Next RowCnt

    I want the formula to run through plugging in the row numbers so that I don't have to write a new set for each row in the table.

    Thank you in advance for the help!
    Attached Files Attached Files
    Last edited by nickt94; 06-17-2020 at 10:39 AM.

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Attempting to create a macro that will use the model to calculate values for a data ta

    It would help if we could see a sample workbook.

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  3. #3
    Registered User
    Join Date
    12-09-2019
    Location
    Antarctica
    MS-Off Ver
    2016
    Posts
    9

    Re: Attempting to create a macro that will use the model to calculate values for a data ta

    I have uploaded the spreadsheet. I'm afraid it will be hard to follow. On the "Data" tab the inputs are cells M through AM and the outputs are columns AN through AS. In the code above you will see where I reference the cells the variables plug in on the "Input & Detail" tab. The macro above currently only calculates the Underwriting NERs for new and renewals. I will have to extend the macro by 4 for sections (market new, market renewal, budget new, budget renewal) to calculate the Market and Budget NERs, but as long as I can prove the macro will work for one section I should be able to get it working for the rest. My hope was to create a macro that will plug in variables and calculate all 6 NERs for each row and have it plug in the row numbers so that it can run through the entire table.

    One last note, a SF of 1,000 has to be input for the calculation to work properly. That is not in the formula.

    Let me know if you need any further clarification.
    Last edited by nickt94; 06-17-2020 at 10:56 AM.

  4. #4
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Attempting to create a macro that will use the model to calculate values for a data ta

    The cells on DATA in columns 25 and 28 for the existing code loop are the only difference I see. What are the columns for the remaining calculations that would differ?

  5. #5
    Registered User
    Join Date
    12-09-2019
    Location
    Antarctica
    MS-Off Ver
    2016
    Posts
    9

    Re: Attempting to create a macro that will use the model to calculate values for a data ta

    You'll see on the Data tab the table has headings saying if its "new" or "renew." There are different sets of information for UW, Market, and Budget and there is a different set for new leases and lease renewals. Every column reference will change when calculating UW, Market, and Budget information but only certain column references will change when calculating new and renewal. For now, I'd just like to get the macro to calculate the UW New and Renewal NERs, because I know I can make the rest of the formula work if it works for one section.

    I'm doing this because the way we have always updated the NERs is by typing in these input ones at a time into the input & detail tab and going back and typing in the NERs it calculates. It often creates mistakes because it is a little meticulous. If I could have a macro preform the task it would make things much easier and more accurate.

  6. #6
    Registered User
    Join Date
    12-09-2019
    Location
    Antarctica
    MS-Off Ver
    2016
    Posts
    9

    Re: Attempting to create a macro that will use the model to calculate values for a data ta

    Please see my attached spreadsheet. I have made some improvements to the Macro. Everything seems to be working correctly, but when I tell the sheet to calculate (Worksheet.calculate) it doesn't appear to be working properly. This causes the values it returns to the data table to all be 0. Not sure what to do about this issue.
    Attached Files Attached Files

  7. #7
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Attempting to create a macro that will use the model to calculate values for a data ta

    There is a problem with the formula in H28. If you evaluate it, the first step errors (a range divided by 12), and returns 0.

  8. #8
    Registered User
    Join Date
    12-09-2019
    Location
    Antarctica
    MS-Off Ver
    2016
    Posts
    9

    Re: Attempting to create a macro that will use the model to calculate values for a data ta

    Thank you so much for helping me! That formula in H28 was suppose to be an array calculation, that was the issue. I do have one question left, I want the formula to check if the row is blank and therefore skip it. Thats why I used the if statement saying if the value doesn't equal blank ("") then do the calculation. I think I set that up wrong. I tried to add "else next RowCnt" to the bottom with no success.

  9. #9
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Attempting to create a macro that will use the model to calculate values for a data ta

    Not exactly sure what it is you're calculating, so I don't know if this is what you're trying to accomplish. That said, try this...
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] first time attempting to create a macro with a variable formula
    By Sunjester in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-19-2019, 12:49 PM
  2. [SOLVED] Attempting to retrieve data from a table with multiple criteria
    By Welshcontingent in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-22-2017, 08:01 PM
  3. [SOLVED] Macro which from given table values will create list
    By igormigor in forum Excel General
    Replies: 6
    Last Post: 11-13-2015, 09:54 AM
  4. Attempting to create macro that finds a value and then transposes that row to a column
    By exoscoriae in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-05-2014, 11:49 AM
  5. Replies: 3
    Last Post: 01-23-2014, 01:30 PM
  6. Attempting Macro to hide current tabs and create new ones with same info (Diff tab name)
    By theta25nupe in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-14-2014, 11:44 AM
  7. Create a model that will generate a column of numbers based on model parameters
    By tncanoeguy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-01-2013, 05:47 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1