Results 1 to 4 of 4

Thread: MACRO: How to import data from sheets.

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    19
    Rep Power
    0

    MACRO: How to import data from sheets.

    Hi all!

    I want to create a macro that transfer data (income statements) from different sheets.

    For example:
    If I choose department 100 and press "Grab Now" button, the data from department 100 will be transfered to the sheet called "transfer to this sheet".

    I have attached my problem Test.xlsx

    Here is the case:
    - I have one excel file with 5 sheets
    - Sheet 1 (Macro Button), has the macro button and a dropdown function where you choose a department of your own choice.
    - Sheet 2 (Transfer to this sheet) is where the chosen data shall be transfered to.
    - Sheet 3 (100) is department "100
    - Sheet 3 (100) is department "101"
    - Sheet 3 (100) is department "102"

    Thank you very much

    Kind Regards

    Jørgen Harsem

  2. #2
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,122
    Rep Power
    10
    Hi

    Try

    Code:
        Dim strDept As String
        Dim wksDest As Worksheet
        
        Set wksDest = Worksheets("Transfer to this sheet")  '<< adjust to suit
        
        strDept = Range("f16").Value2
        
        If Len(strDept) Then
            wksDest.UsedRange.Clear
            On Error GoTo 1
            Worksheets(CStr(strDept)).UsedRange.Copy wksDest.Range("a1")
        End If
        Exit Sub
    1:
        MsgBox "Worksheet '" & strDept & "' does not exist", vbCritical
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    19
    Rep Power
    0
    ah, it works perfect. Thank you very much

    Can you also please explain what dim, strDept, string and Len means?

    thanks again

    Cheers!

  4. #4
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,122
    Rep Power
    10
    Hi

    Have a look at some of these links for a basic understanding of VBA

    Excel VBA Basic Tutorial 1

    Excel VBA tutorial
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

Similar Threads

  1. Macro To Browse Select File And Import Specific Data
    By violetpedal in forum Excel Help
    Replies: 4
    Last Post: 07-17-2013, 07:19 AM
  2. Replies: 3
    Last Post: 06-10-2013, 06:12 PM
  3. Replies: 7
    Last Post: 05-08-2013, 07:12 PM
  4. Macro To Clear Certain Data Across Many Sheets
    By Howardc in forum Excel Help
    Replies: 2
    Last Post: 12-04-2012, 09:10 AM
  5. Replies: 2
    Last Post: 11-08-2012, 01:15 PM

Posting Permissions

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