+ Reply to Thread
Results 1 to 11 of 11

Color Marking of Cells between two cells VBA

  1. #1
    Registered User
    Join Date
    11-27-2020
    Location
    Hannover, Germany
    MS-Off Ver
    MS Office 2016
    Posts
    6

    Color Marking of Cells between two cells VBA

    Hello,

    i want to highlight all cells between 2 filled in cells in a Row. I have the following code which works perfect for columns:

    Public Sub TEST()
    Dim objCell As Range
    Dim strAddress As String
    Set objCell = Columns(2).Find(What:="XX", _
    After:=Cells(Rows.Count, 2), LookIn:=xlFormulas, _
    LookAt:=xlWhole)
    If Not objCell Is Nothing Then
    strAddress = objCell.Address
    Set objCell = Columns(2).FindNext(objCell)
    If strAddress <> objCell.Address Then _
    Range(Range(strAddress), objCell.Offset(0, 0)).Interior.ColorIndex = 5
    End If
    End Sub

    My VBA knowledge is unfortunately not sufficient to rewrite the code, so that instead of column, e.g. row 3 is searched and marked. Can you help me out with this?

    Regards,
    Max

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Color Marking of Cells between two cells VBA

    Use Rows instead of Columns.
    Rory

  3. #3
    Registered User
    Join Date
    11-27-2020
    Location
    Hannover, Germany
    MS-Off Ver
    MS Office 2016
    Posts
    6

    Re: Color Marking of Cells between two cells VBA

    I tried this already and get the following error message: Types incompatible

    Set objCell = Rows(3).Find(What:="XX", _
    After:=Cells(Columns.Count, 2), LookIn:=xlFormulas, _
    LookAt:=xlWhole)

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Color Marking of Cells between two cells VBA

    If you're looking in row 2, then the After argument has to be in row 2 if you specify it. Your arguments for cells are the wrong way round:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-27-2020
    Location
    Hannover, Germany
    MS-Off Ver
    MS Office 2016
    Posts
    6

    Re: Color Marking of Cells between two cells VBA

    I still get the same Error Message (Run Time Error 13):

    Attachment 706112

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Color Marking of Cells between two cells VBA

    Sorry that should be a 3 not 2 - I misread which row you were searching.

  7. #7
    Registered User
    Join Date
    11-27-2020
    Location
    Hannover, Germany
    MS-Off Ver
    MS Office 2016
    Posts
    6

    Re: Color Marking of Cells between two cells VBA

    Oh yes - you´re a genious. It works perfectly now. Thank you so much!

  8. #8
    Registered User
    Join Date
    11-27-2020
    Location
    Hannover, Germany
    MS-Off Ver
    MS Office 2016
    Posts
    6

    Re: Color Marking of Cells between two cells VBA

    Ok here is just another question. Macro is working perfectly.

    Now I want this macro to be executed for each line (5-200). How can I write a loop for this so that I don't have to copy the macro 195x?Attachment 706455

  9. #9
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Color Marking of Cells between two cells VBA

    Add a loop:

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    11-27-2020
    Location
    Hannover, Germany
    MS-Off Ver
    MS Office 2016
    Posts
    6

    Re: Color Marking of Cells between two cells VBA

    Hi rorya,

    I wish I had this knowledge myself. With it you can save so much time...

    It works perfectly, thanks again!

  11. #11
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Color Marking of Cells between two cells VBA

    You can get there - just takes time, and a willingness to have a go.

+ 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. Comparing 2 sheets and marking the different cells
    By cramnij in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-08-2016, 02:46 PM
  2. Marking specific Cells with color ( Tried Conditional Formating)
    By tskid11 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-10-2015, 11:44 PM
  3. [SOLVED] Marking Complete/Incomplete if ALL cells have value
    By bclayto2 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-29-2013, 03:26 PM
  4. Marking duplicate cells
    By cp49321 in forum Excel General
    Replies: 1
    Last Post: 02-09-2012, 02:19 PM
  5. marking linked cells
    By kuege in forum Excel General
    Replies: 0
    Last Post: 07-10-2008, 12:12 PM
  6. Marking changed value cells
    By Gerard FREDERIC in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-13-2008, 12:08 AM
  7. Marking changed value cells
    By Gerard FREDERIC in forum Excel General
    Replies: 1
    Last Post: 06-12-2008, 02:35 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