Results 1 to 3 of 3

need help with macro code problem

Threaded View

  1. #1
    Registered User
    Join Date
    05-12-2015
    Location
    Mozambique
    MS-Off Ver
    MS Office 2013
    Posts
    6

    need help with macro code problem

    I'm trying to create code to insert data from one workbook to another workbook obeying some criteria, however the code I created have error "run-time error '9' subscript out of range". Am beginner in vba. Below is the code:

    Sub ImportBaseII()
    
    Dim i As Integer
    Dim j As Integer
    Dim k As Integer
    Dim BaseII As Workbook, Base As Workbook
    Dim BEmpPublic As Worksheet
    Dim vFile As Variant
    
    'Set source workbook
    Set BaseII = ActiveWorkbook
    'Open the target workbook
    vFile = Application.GetOpenFilename("Excel-files,*.xlsx", _
    1, "Select One File To Open", , False)
    'if the user didn't select a file, exit sub
    If TypeName(vFile) = "Boolean" Then Exit Sub
    Workbooks.Open vFile
    'Set targetworkbook
    Set Base = ActiveWorkbook
    
    For i = 0 To 197
    
    k = 11 + i * 5
    
    j = i + 2
    
    'For instance, copy data from a "range" in the first workbook to another range in the other workbook
    Base.Worksheets("EPúblic").Cell(1, k).Value = BaseII.Worksheets("BEmpPublic").Cell(2, j).Value
    
    t = 12 + i * 5
    
    Base.Worksheets("EPúblic").Cell(7, t).Value = BaseII.Worksheets("BEmpPublic").Cell(6, j).Value
    
    n = 14 + i * 5
    
    Base.Worksheets("EPúblic").Cell(7, n).Value = BaseII.Worksheets("EmpPublic").Cell(7, j).Value
    
    Next i
    
    MsgBox ("Done")
    
    End Sub
    Someone help me, thank you in advance.
    Last edited by Dimy; 06-17-2015 at 08:36 AM. Reason: post does not comply with forum Rule

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro to copy Code / Macro Code / 2 Sheets
    By paxile2k in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-23-2014, 12:59 AM
  2. [SOLVED] Code to create Macro Button and Assigning Macro code
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-10-2014, 11:30 AM
  3. [SOLVED] Excel Macro Visual Basic code not looking at all sheets with second section of code.
    By Heinrich Venter in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-10-2014, 08:26 AM
  4. [SOLVED] Code with last column and last row to recognize multiple commands through the macro code
    By kosherboy in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-13-2014, 04:10 PM
  5. Replies: 0
    Last Post: 05-06-2013, 05:45 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1