Solved

Excel VBA Using a function in a cell to pull in data from different sheets

Posted on 2013-11-19
4
389 Views
Last Modified: 2013-11-24
Hi

I have several workbooks with data in a similar format.
I know that you can call a VBA function in a cell.
Does anyone have an example where this technique is used to pull
data from several sheets into one?
0
Comment
Question by:murbro
[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
4 Comments
 
LVL 33

Expert Comment

by:Rob Henson
ID: 39660741
You need to be more specific about what you are trying to achieve.

Sample data is always good but must be non-confidential as it is viewable to public.

Thanks
Rob H
0
 
LVL 8

Assisted Solution

by:stevepcguy
stevepcguy earned 250 total points
ID: 39660743
I'm not great at pounding out code, but I can copy existing code and tweak it to suit my situation.
Here is an example of copying from another worksheet. It's not what you asked for, but simplifies the process:
http://www.ehow.com/how_7361777_copy-paste-another-using-vba.html

Once you wrap your head around that, check out how to copy from another workbook:
http://www.ozgrid.com/forum/showthread.php?t=69320
0
 
LVL 12

Accepted Solution

by:
Harry Lee earned 250 total points
ID: 39667294
To be able to use VBA in spreadsheet cells, you have to create the function in VBA so that it will work like other formulas.

Open up VBA Editor but pressing Alt-F11. Open Project Explorer by pressing Ctrl-R.

In the Project Explorer, look for the current file you are working on. Right click and choose Insert -> Module.

In the module, type in some like the bellow.

Function GetQuarterEnd(Rngdate As Range) As Date
Dim myDateVariable As Date
Dim Year1, Month1, Day1, ResultMth, ResultDate As Integer

Year1 = Year(Rngdate.Value)
Month1 = Month(Rngdate.Value)
Day1 = Day(Rngdate.Value)

Select Case Month1
    Case 1 To 3
        ResultMth = 3
    Case 4 To 6
        ResultMth = 6
    Case 7 To 9
        ResultMth = 9
    Case 10 To 12
        ResultMth = 12
End Select

Select Case ResultMth
    Case 3, 12
        ResultDate = 31
    Case 6, 9
        ResultDate = 30
End Select
myDateVariable = DateSerial(Year1, ResultMth, ResultDate)
GetQuarterEnd = myDateVariable
End Function

Open in new window


After that, you can start using formula like =GetQuarterEnd(A1) in spreadsheet cells.

In you question, you said you want to put data from multiple sheet into one. That doesn't sound like it has anything to do with calling VBA function from spreadsheet cells.
0
 

Author Closing Comment

by:murbro
ID: 39672314
Thanks
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

726 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