+ Reply to Thread
Results 1 to 15 of 15

Macro that can fill up entire row with color if condition is true

  1. #1
    Registered User
    Join Date
    02-07-2019
    Location
    Sao Paulo - Brazil
    MS-Off Ver
    2018
    Posts
    14

    Macro that can fill up entire row with color if condition is true

    Hello everyone,

    I am new to this VBA Excel thingy but I am loving it. I still dont know a lot of it but I figured someone might be able to help me out with a couple macros that I have been working on.

    1º So the first macro that I am trying to do is:

    Sub LocalizarComp()

    Código = InputBox("Qual o código a ser localizado?")

    Dim myrange As Range

    Set myrange = ThisWorkbook.Worksheets("Localizacao").UsedRange

    For Each cell In myrange.Cells

    If cell.Value = Código Then

    cell.Interior.Color = 184204228

    End If

    Next

    End Sub
    What the macro does now is if the code I put in the InputBox is true, it will fill up the cell with the color mentioned above. What I actually want the macro to do is if the code is true, select the entire row until last row cell being used and fill all the cell with the color mentioned (Lets say it goes until row L). It might not be as hard but since I am new it's kinda complicated for me.

    Thanks for your time,
    Attached Images Attached Images
    Last edited by Skroxzim; 02-07-2019 at 02:40 PM. Reason: Solved

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Help me with a couple Macros

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title go to your first post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: Help me with a couple Macros

    Try the following code.

    Please Login or Register  to view this content.
    if you want to "paint" more then one cell you need Cells to setup the paintrange..
    cells.row = to make sure to paint the row the for each loop is currently on
    1 = for column 1 of column A.
    .resize will select multiple cells in this case 1 row high and X columns wide based on the Columns.count

  4. #4
    Registered User
    Join Date
    02-07-2019
    Location
    Sao Paulo - Brazil
    MS-Off Ver
    2018
    Posts
    14

    Macro that can fill up entire row with color if condition is true

    any help please?
    Last edited by Skroxzim; 02-07-2019 at 12:18 PM.

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,806

    Re: Macro that can fill up entire row with color if condition is true

    Be patient.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  6. #6
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: Macro that can fill up entire row with color if condition is true

    From the pm I got from you I understand you need a little different code because inputbox result is only lookup in column A and you want to color all cells that have a value filled but the last column filled can vary per row

    Lets see if this code works better.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-07-2019
    Location
    Sao Paulo - Brazil
    MS-Off Ver
    2018
    Posts
    14

    Re: Macro that can fill up entire row with color if condition is true

    Quote Originally Posted by Roel Jongman View Post
    From the pm I got from you I understand you need a little different code because inputbox result is only lookup in column A and you want to color all cells that have a value filled but the last column filled can vary per row

    Lets see if this code works better.

    Please Login or Register  to view this content.
    Ok so what I meant with the lookup is the code that I am gonna put on inputbox can only be found in column A, idk if that helps or not but I wont be putting something that can be found per say on column C, or D.

    With the code that I started with it will look up for the code I put on the inputbox and will fill up cell with color mentioned above, what I want is to find the cell with the inputbox code and color from column A to column L (as shown in the picture, is the last cell being used, not necessarily going to be the last one being written on tho.

  8. #8
    Registered User
    Join Date
    02-07-2019
    Location
    Sao Paulo - Brazil
    MS-Off Ver
    2018
    Posts
    14

    Re: Macro that can fill up entire row with color if condition is true

    Quote Originally Posted by Roel Jongman View Post
    From the pm I got from you I understand you need a little different code because inputbox result is only lookup in column A and you want to color all cells that have a value filled but the last column filled can vary per row

    Lets see if this code works better.

    Please Login or Register  to view this content.
    btw that code did not work,

    here is why:
    Attached Images Attached Images

  9. #9
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: Macro that can fill up entire row with color if condition is true

    Oh, boy the joy of VBA, took a while to figure out my mistake..
    (I used .End(xlRight) and must be .End(xlToRight) )

    try this one..
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    02-07-2019
    Location
    Sao Paulo - Brazil
    MS-Off Ver
    2018
    Posts
    14

    Re: Macro that can fill up entire row with color if condition is true

    Quote Originally Posted by Roel Jongman View Post
    Oh, boy the joy of VBA, took a while to figure out my mistake..
    (I used .End(xlRight) and must be .End(xlToRight) )

    try this one..
    Please Login or Register  to view this content.
    Thanks for the reply Roel, it worked better but still not exactly what I want, I think that the easiest way would be just to fill up cells until column "N" since some of the cells does not contain data on it. I think thats what it happened to the the code you made, it will stop filling up cells until last one used maybe?

  11. #11
    Registered User
    Join Date
    02-07-2019
    Location
    Sao Paulo - Brazil
    MS-Off Ver
    2018
    Posts
    14

    Re: Macro that can fill up entire row with color if condition is true

    *forgot to upload image on last post sorry
    Attached Images Attached Images

  12. #12
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: Macro that can fill up entire row with color if condition is true

    ok, for it to go to fixed columns A:N

    replace the cells line with
    Please Login or Register  to view this content.
    14 will make it go to N
    if you want shorter or longer (before you mentioned column L) you can change that number.

    If this still does not work than you will have to upload an example file (excel workbook)
    where you than also show the result painted manually on a few example rows. because we are now going back and forth a lot on what looks like a simple problem..
    Last edited by Roel Jongman; 02-07-2019 at 02:30 PM.

  13. #13
    Registered User
    Join Date
    02-07-2019
    Location
    Sao Paulo - Brazil
    MS-Off Ver
    2018
    Posts
    14

    Re: Macro that can fill up entire row with color if condition is true

    HEY IT WORKS PERFECT NOW! Thank you so much for your patience with me! Really glad you could help me out with this

    Now lets try helping me with my other macro haha, jkjk but if any of you are trying to help the thread name is "Macro that will update changed data from one sheet to another sheet" :>
    Last edited by AliGW; 02-07-2019 at 03:15 PM.

  14. #14
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: Macro that can fill up entire row with color if condition is true

    Ok thats great, glad to help..

    If this thread is solved you can mark it as solved by going to the gray bar just above your opening post on the right side there is a menu called "Thread tools" click it and then click the Thread is solved option..
    then everybody is happy

  15. #15
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,806

    Re: Macro that can fill up entire row with color if condition is true

    Please don't quote whole posts, especially when you are responding to the one immediately preceding your own - it's just clutter. It's OK to quote if you are responding to a post out of sequence, but limit quoted content to a few relevant lines that makes clear to whom and what you are responding. Thanks!

    For normal conversational replies, try using the QUICK REPLY box below.

+ 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. A couple of questions
    By kingdt in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-26-2007, 07:41 AM
  2. a couple of questions
    By moshmoshon in forum Excel General
    Replies: 2
    Last Post: 08-31-2007, 05:31 PM
  3. A couple of questions...
    By Punk0Rama in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 09-08-2006, 07:36 PM
  4. A couple of questions...
    By littlegreenmen1 in forum Excel General
    Replies: 0
    Last Post: 06-10-2005, 04:40 PM
  5. [SOLVED] Couple more questions...
    By Poor microsoft user in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 04-27-2005, 02:47 PM

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