Wednesday, 15 July 2015

How to define an object inside a for loop for excel vba -


I want to import data from multiple workbooks, all from the same sheet index (3) I am new to VBA, and I came to know how to open more than one file, and copy one file from one sheet to another file in another sheet in a separate workbook, but let me understand this It does not seem to be that how many files I highlighted where the error is, it tells me "the object does not support this property or method"

Can you please help Are you Thank you sub-dataimport () 'set Vars dim ArbinBook as workbook, DataBook workbook dim I as integer, J as integer dim caption as string dim ArbinFile version, datafile The formulas are set to make 'weak assumption' as to the active workbook goal set Data Book = Application.ActiveWorkbook 'received Arbin workbook caption = "Please select the input file" to set the' open destination ':' ChDrive (' '' CHDIR ("e: \ chapters \ chap14") Finally it creates an array arbinFile = Application.GetOpenFilename creates "arbinfile" version, with "application" (as, "correct", caption, it True) 'Exit' when not canceling IsArray (arbinFile) then MsgBox "No file selected". Exit sub-end then set the default targetSheet targetSheet = DataBook.Sheets (1) 'ArginFile' for each integer array I selected in Arbinfile "ArbinFile" (ArbinFile) for ArbinBook = Workbooks.Open ( As an ArbinFile worksheet set (i)) targetSheet.Range ("A2", "G150"). Price = ArbinBook.Sheets (3) .Range ("A2", "G150") Price ** ** Workbook Error in the above line (datasheet) .Activate 'Reactivate Data Book Workbook (1) .Activate' Activate Data Sheet ActiveWorkbook.Sheets again (1) .Copy _ after: = ActiveWorkbook. Activate Sheets (1) workbooks (ArbinFile (1).) 'Arbin again activate book (i) ArbinBook.Close Next I beep ending sub

My instinct tells me that ArbinBook.Sheets (3) is a chat sheet, not a worksheet (or, at least In, it is a somewhat worksheet addition) it may be hidden, but it will still be indexed as (3).

If so, then sheet (3) to worksheet (3) .

Added : If BTW is true, it also shows why use of an index-number is unbelievable. If possible, see the worksheet by its name. (I appreciate it that it can not always be possible.)

Added (from comments) nothing in your code with the name DataSheet is. Add option clear at the top of your module.

No comments:

Post a Comment