+ Reply to Thread
Results 1 to 3 of 3

writing vba code to fill in column of sheet, formula works vba code will not

  1. #1
    Registered User
    Join Date
    02-27-2019
    Location
    portland, oregon
    MS-Off Ver
    2016
    Posts
    2

    writing vba code to fill in column of sheet, formula works vba code will not

    I am trying to write a formula in VBA do fill a column in a excel sheet. I can do the formula in a cell on a cell by cell basis but I want to copy this formula to the worksheet by VBA. This worksheet can be of varying lengths from 2000 rows to 10,000 rows. The data is imported into excel and I want to get another piece of statistical data from it. The data that is imported is 11 columns wide with the first column always with data the other columns may or may not have data on any given row.
    I am looking to add a formula in column 12 that looks at data in column 2 depending on information in column 10 as to how big this range of data may be. I am calculating the min value for this range of data.
    There is a value placed in column’s 9, 10 and 11 at the start of the data range in column 2. Each value in each row reflects a 4 sec time reading. The value in column 10 reflects the seconds of this data range (23sec), so the rows would be the value of column 10/4 rounded to nearest whole number.
    Given this information I am trying to calculate the min value in this range. This range will vary over the data set, from 3-4 rows to as many as 400+ rows. This is based on the value in column 10 at the first row of this range in column 2. An example of this would be
    Rows
    A B C D E F G H I J L K
    1 2 3 4 5 6 7 8 9 10 11 12 (Column)
    1 1/3/2019 04:09:44 92 80
    2 1/3/2019 04:09:48 92 79
    3 1/3/2019 04:09:52 92 79
    4 1/3/2019 04:09:56 92 78
    5 1/3/2019 04:10:00 91 78 start 23 8 ???
    6 1/3/2019 04:10:04 90 78
    7 1/3/2019 04:10:08 90 77
    8 1/3/2019 04:10:12 89 77
    9 1/3/2019 04:10:16 89 78
    10 1/3/2019 04:10:20 90 77
    11 1/3/2019 04:10:24 92 77
    12 1/3/2019 04:10:28 92 78


    The data range starts on the row that is filled with data in column’s 9-11 and extends the # of rows reflected in cell J5 (23/4 = 6) rows down. I want to fill in the data in row 5 column 12(K).

    The formula that works when placed in that cell is:
    =IF(INDIRECT("I"&(ROW()))<>"Desat start",””,MIN(INDIRECT("B"&(ROW())):INDIRECT("B"&((ROW()+ROUND(J5/4,0)+1)))))

    I want to put this in K1 and then copy down the whole sheet, because I don’t know where the column’s 9 – 11 will have data in them. When there is data, the formula will calculate the min for that range, if no data in Column’s 9 – 11 it will leave it blank.

    When I try to use the R[?]C[?] notation in VBA it stars to break down and will not work in the editor. How do I write this formula in VBA so I can fill this column? Because Data in column 9-11 is sporadic, the only way I’ve found to do this is to put the formula in all of the rows.

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: writing vba code to fill in column of sheet, formula works vba code will not

    pdx2245, welcome to the forum.

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Registered User
    Join Date
    02-27-2019
    Location
    portland, oregon
    MS-Off Ver
    2016
    Posts
    2

    Re: writing vba code to fill in column of sheet, formula works vba code will not

    thanks I'll get that together

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 07-02-2018, 07:32 PM
  2. Replies: 0
    Last Post: 07-05-2017, 09:36 PM
  3. [SOLVED] writing fill default code efficiently
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-29-2015, 07:27 PM
  4. Writing a Formula using R1C1 code in VBA code
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-15-2014, 11:06 AM
  5. Replies: 6
    Last Post: 11-28-2012, 07:29 PM
  6. Writing code to fill a column
    By dalewms2 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-31-2011, 04:03 PM
  7. Writing active sheet code
    By dalewms2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-31-2011, 12:48 PM

Tags for this Thread

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