anthony vba populating

Public Schedule Face-to-Face & Virtual Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Anthony - vba populating table from an external workbook

Anthony - vba populating table from an external workbook

resolvedResolved · High Priority · Version 2010

Steven has attended:
Access Intermediate course

Anthony - vba populating table from an external workbook

Hi,

I need to populate a table on a worksheet with information from another workbook, i am aiming to populate one table with info from many sheets on another file. The file used will be based on a userform combo box selection of which there are two choices.

On the external workbook the sheets are named "T64 v" T71 v" etc, i would like to use the first three characters for example "T64" to be part of my table under the heading T-Dept.

Could you provide an example of code that can -

1. take data from a range in an external workbook and place it on the active worksheet. Assume that the external workbook is saved in C:\Desktop and called Budget_Model.xlsx

2. put the first (left) three characters of the sheet (tab) name from the external workbook into a cell on the active worksheet.

Thanks in advance for your help with this query.

Steve

RE: Anthony - vba populating table from an external workbook

Hi Steve. Here's a basic example of what you're after. You'll need to put the files in place and rename the sheets accordingly for this example to work. Once you've got the relevant workbook in memory as wbOpen, I'm hoping the rest will become obvious!

Here's the code:

***

Option Explicit

Sub GetMyData()

Dim wbOpen As Workbook
Dim myarray As Variant
Dim shtName As String

Application.ScreenUpdating = False
Application.DisplayAlerts = False

Set wbOpen = Workbooks.Open("c:\desktop\Budget_Model.xlsx")

myarray = wbOpen.Sheets("T64 v").Range("a1:a3").Value

wbOpen.Close SaveChanges:=False

Sheets("Results").Range("a1:a3").Value = myarray

Sheets("Results").Range("b1").Value = Left("T64 v", 3)

Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

***

Hope this helps,

Anthony

RE: Anthony - vba populating table from an external workbook

Worked perfectly.

Thanks for the assistance.

Steve

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Paste functions box quickly

If you want to do a formula using the paste functions box press SHIFT + F3.

View all Excel hints and tips


Server loaded in 0.06 secs.