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

anthony vba populating

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

ResolvedVersion 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:

Move data worksheet to worksheet

To move data from one worksheet to another, highlight the data.

Select and hold down the ALT key and position the mouse on the border of the selection until the mouse pointer displays four-headed arrows.

Drag the selection down to the destination worksheet tab.

When the arrow touches the tab, Excel switches to the desired worksheet. Now drag the selection to the correct position. Let go of the mouse and then the ALT key.

To copy data from one worksheet to another, select and hold down the CTRL+ALT keystroke combination and perform the steps above.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.