[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Formula View-Follow Up

Posted on 2012-12-27
5
Medium Priority
?
399 Views
Last Modified: 2012-12-27
This is follow up to this previous question
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_27977620.html#a38724213

How can the formula components be listed in a dynamic way, assuming there are 18 components?

Thanks
0
Comment
Question by:Rayne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 26

Expert Comment

by:redmondb
ID: 38724774
Hi, Rayne.

Please let us know the address range of the 18 components - assuming that the actual formulas are in D8 to D30 and the results are in F8 to F30

Thanks,
Brian.
0
 
LVL 26

Accepted Solution

by:
redmondb earned 2000 total points
ID: 38724929
Rayne,

In the attached, I've assumed that you simply pushed the components down to make room for the extra formulas. The code is...
Option Explicit

Const XFORMULAS = "D8:D30"
Const XCOMPONENTS = "C32:C49"

Private Sub Worksheet_Change(ByVal Target As Range)
Dim xCell   As Range
Dim xArray  As Variant
Dim xLoaded As Boolean
Dim xHold   As String
Dim i       As Long

If Intersect(Target, Union(Range(XFORMULAS), Range(XCOMPONENTS))) Is Nothing Then Exit Sub

Application.EnableEvents = False
Application.ScreenUpdating = False

    For Each xCell In Range(XFORMULAS)
        xHold = xCell.Formula
        If Mid(xHold, 1, 1) = "=" Then
            If Not xLoaded Then
                xArray = WorksheetFunction.Transpose(Range(XCOMPONENTS).Value)
                xLoaded = True
            End If
            For i = 1 To UBound(xArray)
                If xArray(i) <> "" Then xHold = Replace(xHold, Replace(Range("D31").Offset(i, 0).Address, "$", ""), xArray(i))
            Next
            xCell.Offset(0, 2) = "'" & xHold
        Else
            xCell.Offset(0, 2) = ""
        End If
    Next

Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub

Open in new window

Edit: Minor change to blank out a row's result if it has no formula.

Brian.readAndDisplyFormulas-V3.xlsm
0
 

Author Comment

by:Rayne
ID: 38725491
Hello Brian,

Simply speaking –You Rock.  ALL Hats off to you!!
Thanks for the effort you put in here.

Thank you :)
0
 

Author Closing Comment

by:Rayne
ID: 38725492
Perfect Solution!!
0
 
LVL 26

Expert Comment

by:redmondb
ID: 38725553
Thanks, Rayne. Glad you're sorted!
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question