+ Reply to Thread
Results 1 to 6 of 6

writing formula in range on each sheet via array

  1. #1
    Forum Contributor
    Join Date
    03-24-2009
    Location
    Vietnam
    MS-Off Ver
    Excel 2010
    Posts
    382

    writing formula in range on each sheet via array

    Hi,

    I am trying to write a formula on each sheet in a range which is not clearly defined on each sheet on the book. excel is complaining my range object and I am not seeing it today (coding too much....). Anyone can point me there?

    Please Login or Register  to view this content.
    thanks,
    A2k

  2. #2
    Forum Contributor
    Join Date
    03-24-2009
    Location
    Vietnam
    MS-Off Ver
    Excel 2010
    Posts
    382

    Re: writing formula in range on each sheet via array

    word of advice, never think you can code at 4am...

    solution: select the sheets before fiddling on it
    Please Login or Register  to view this content.
    sorry for bothering, good night.
    A2k

  3. #3
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    2003, 2007, 2010, 2013
    Posts
    1,252

    Re: writing formula in range on each sheet via array

    Even better, avoid Select / Selection altogether. Something like this?

    Please Login or Register  to view this content.
    Hope that helps,

    Colin

    RAD Excel Blog

  4. #4
    Forum Contributor
    Join Date
    03-24-2009
    Location
    Vietnam
    MS-Off Ver
    Excel 2010
    Posts
    382

    Re: writing formula in range on each sheet via array

    hmm... out of curiosity because I dont use this approach very often:

    1. why not selecting cells? performance slowdown?
    2. you starting from the last row upwards to see if there is content, if no then skip, if yes write formula. However, are you really starting at the last row? I dont see you see you determine cell content from A65536 upwards... how do you know where is the last row?
    3. what exactly is "Cstr" doing? Cell String?

    would love to know...
    Thanks,
    A2k

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: writing formula in range on each sheet via array

    probably the same result:

    Please Login or Register  to view this content.



  6. #6
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    2003, 2007, 2010, 2013
    Posts
    1,252

    Re: writing formula in range on each sheet via array

    1. why not selecting cells? performance slowdown?
    Yes. That and also you can't select a range unless it is on the active sheet, so you have to select the sheet too. There are some situations where you have to select cells, but this isn't one of them.
    2. you starting from the last row upwards to see if there is content, if no then skip, if yes write formula. However, are you really starting at the last row? I dont see you see you determine cell content from A65536 upwards... how do you know where is the last row?
    I determine it on this line here:
    Please Login or Register  to view this content.
    ws.Rows.Count will return the number of rows on the worksheet. For you, this will be 65536. I explicitly convert the number into a string "65536" using CStr() and then concatenate it with "A" to give me "A65536". I then use the Range.End(xlUp) method (since I based the approach on the code you provided) to get the last row in column A with data in.
    3. what exactly is "Cstr" doing? Cell String?
    See my answer to (2) and also have a look at the "Type Conversion Functions" topic in your VBA helpfile. If you google for implicit and explicit data type conversions you will find plenty of material on the subject.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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