none
Which is the best approach to read/write data from multiple sheet using vba code? RRS feed

  • Question

  • Hi

    Which is the best approach to read/write data from multiple sheet using vba code? And I want to know the reason why Approach1/Approach2 is best?

    Approach 1

    Without activating particular sheet by using

    sheets(<sheetname>).Range("A1").value=XYZ

    Approach 2

    Activating particular sheet by using

    sheets(<sheetname>).Activate
    Range("A1").Value = XYZ


    Bala

    Monday, June 6, 2016 2:54 PM

Answers

All replies

  • Hi

    Which is the best approach to read/write data from multiple sheet using vba code? And I want to know the reason why Approach1/Approach2 is best?

    Approach 1

    Without activating particular sheet by using

    sheets(<sheetname>).Range("A1").value=XYZ

    Approach 2

    Activating particular sheet by using

    sheets(<sheetname>).Activate
    Range("A1").Value = XYZ


    Bala

    Monday, June 6, 2016 2:54 PM
  • >>>Which is the best approach to read/write data from multiple sheet using vba code? And I want to know the reason why Approach1/Approach2 is best?

    According to your description, I think that there are no which Approach1 or Approach2 is best, when you choose Approach1 or Approach2,it is based on your real requirement.

    In addition when you choose Approach2, you need to note:

    When it’s used without an object qualifier (an object to the left of the period), the Range property returns a range on the active sheet. If the active sheet isn’t a worksheet, the method fails. Use the Activate method to activate a worksheet before you use the Range property without an explicit object qualifier.

    For more information, click here to refer about Range Object (Excel)

    • Proposed as answer by David_JunFeng Sunday, June 19, 2016 2:34 PM
    Tuesday, June 7, 2016 5:44 AM
  • Honestly, I don't think it makes a material difference. 

    MY BOOK

    • Marked as answer by David_JunFeng Monday, June 20, 2016 2:25 PM
    Friday, June 10, 2016 1:07 AM