+ Reply to Thread
Results 1 to 10 of 10

Excel Marco: fill cells based on value in adjacent cell

  1. #1
    Registered User
    Join Date
    11-07-2019
    Location
    Ontario, Canada
    MS-Off Ver
    2013
    Posts
    15

    Excel Marco: fill cells based on value in adjacent cell

    Hello,
    I have this working macro button that will "reset all status" in the range B2:B15 to a default prompt for my colleagues to indicate job's status:
    macro.png

    Private Sub CommandButton1_Click()
    Sheets("Sheet1").Range("B2:B15").Value = "please enter status"
    End Sub


    I want this macro to stop populating the value "please enter status" in the B column if there are no values in adjacent A column. Looking at screenshot it would leave B6:B15 empty.

    Appreciate your help!

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: Excel Marco: fill cells based on value in adjacent cell

    How about
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    11-07-2019
    Location
    Ontario, Canada
    MS-Off Ver
    2013
    Posts
    15

    Re: Excel Marco: fill cells based on value in adjacent cell

    it is just filling the column to infinity
    macro.png
    Attached Images Attached Images

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: Excel Marco: fill cells based on value in adjacent cell

    In that case column A is not blank. Do you have formulae in there?

  5. #5
    Registered User
    Join Date
    11-07-2019
    Location
    Ontario, Canada
    MS-Off Ver
    2013
    Posts
    15

    Re: Excel Marco: fill cells based on value in adjacent cell

    yes, sorry. the job numbers are vlookup results in column A

  6. #6
    Registered User
    Join Date
    11-07-2019
    Location
    Ontario, Canada
    MS-Off Ver
    2013
    Posts
    15

    Re: Excel Marco: fill cells based on value in adjacent cell

    I have this recommendation from another forum,
    but it ignores the zero vlookup value in column A.
    I want this macro to stop if adjacent is "0"
    Private Sub CommandButton1_Click()
    Dim rng as Range
    Set rng = Sheets("Sheet1").Range("A2:A15")

    If Application.CountA(rng) > 0 Then
    rng.SpecialCells(xlCellTypeFormulas).Offset(,1).Value = "please enter status"
    End If
    End Sub

  7. #7
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Excel Marco: fill cells based on value in adjacent cell

    Since your range is fixed in size, then this macro should work for you...
    Please Login or Register  to view this content.

  8. #8
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Excel Marco: fill cells based on value in adjacent cell

    Quote Originally Posted by pkobzar View Post
    I want this macro to stop if adjacent is "0"
    Could you explain this in a little more detail (maybe show an example) as you did not mention this in your original post.

  9. #9
    Registered User
    Join Date
    11-07-2019
    Location
    Ontario, Canada
    MS-Off Ver
    2013
    Posts
    15

    Re: Excel Marco: fill cells based on value in adjacent cell

    sure, this is my ultimate result: statuses are reset to SCHEDULED with a click of the Button,
    but zeros in row 33 are ignored and status is not populated for cell E33
    Columns B,C,D are vlookup values.
    Attached Images Attached Images
    Last edited by pkobzar; 11-15-2019 at 05:24 PM.

  10. #10
    Registered User
    Join Date
    11-07-2019
    Location
    Ontario, Canada
    MS-Off Ver
    2013
    Posts
    15

    [solved] Excel Marco: fill cells based on value in adjacent cell

    [solved] on another forum, but I'm too fresh here to post links, will update when I "grow up".
    solution #1:
    Please Login or Register  to view this content.
    solution #2 (also works if adjacent cells are not Constants, but Formulas)
    Please Login or Register  to view this content.
    solution #3
    Please Login or Register  to view this content.
    Last edited by pkobzar; 11-19-2019 at 09:25 AM.

+ 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. [SOLVED] Fill Adjacent Cell with 0-30/30+/60+/90+ Past Due based on Dates in Column
    By Excelrookie01 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-09-2017, 01:08 PM
  2. Automatically Fill Adjacent Cells Based On Input Data
    By maxraph in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-26-2012, 01:04 PM
  3. Auto-fill adjacent cells based on start/stop date?
    By jeffreyray in forum Excel General
    Replies: 3
    Last Post: 10-03-2011, 06:49 PM
  4. fill/ remove formula based on adjacent cell value
    By sarails in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-14-2011, 10:38 PM
  5. Formatting Cell Fill Based on Adjacent Value
    By bmossman in forum Excel General
    Replies: 2
    Last Post: 11-22-2006, 02:44 PM
  6. [SOLVED] Conditional coloring of Excel cells, based on adjacent cell values?
    By Greg Stuart in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-10-2006, 06:20 PM
  7. Apply cell shading based on adjacent cells in EXCEL
    By garywr in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-10-2005, 09:05 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