need help with VBA code to reference column header to delete value highlighted in green

rlabomba

New Member
Joined
Jun 30, 2014
Messages
3
Hi There,
So this might be a confusing one. I need a macro to go to the column labeled (LSL) and look left until it sees the first cell with data, then I want to delete row that the latest cell highlighted in green. not sure where to start but I think i'm confusing myself. So, in laymen terms I need the macro to go to column labeled LSL, look left cell by cell and find the first non-blank cell, if that cell is green delete entire row, shift cells up, if any other color just ignore and move on. I hope that makes it a little clearer.

open
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hello,

This isn't the most efficient code.

Code:
Sub DELETE()
    For FIND_COLS = 1 To Cells(1, Columns.Count).End(xlToLeft).Column
        If Cells(1, FIND_COLS).Value = "LSL" Then
            MY_COL = FIND_COLS
            GoTo cont
        End If
    Next FIND_COLS
cont:
    For MY_ROWS = Cells(Rows.Count, MY_COL).End(xlUp).Row To 2 Step -1
        For MY_COLS = FIND_COLS - 1 To 1 Step -1
            If Not IsEmpty(Cells(MY_ROWS, MY_COLS).Value) Then
                If Cells(MY_ROWS, MY_COLS).Interior.Color = 5287936 Then
                    Rows(MY_ROWS).DELETE
                End If
                GoTo MY_NEXT
            End If
        Next MY_COLS
MY_NEXT:
    Next MY_ROWS
End Sub

But I think it works. You will need to play around with the colour number, depending on which green you are using.
 
Last edited:
Upvote 0
HEYYYYYY...worked! Thanks alot!!

Hello,

This isn't the most efficient code.

Code:
Sub DELETE()
    For FIND_COLS = 1 To Cells(1, Columns.Count).End(xlToLeft).Column
        If Cells(1, FIND_COLS).Value = "LSL" Then
            MY_COL = FIND_COLS
            GoTo cont
        End If
    Next FIND_COLS
cont:
    For MY_ROWS = Cells(Rows.Count, MY_COL).End(xlUp).Row To 2 Step -1
        For MY_COLS = FIND_COLS - 1 To 1 Step -1
            If Not IsEmpty(Cells(MY_ROWS, MY_COLS).Value) Then
                If Cells(MY_ROWS, MY_COLS).Interior.Color = 5287936 Then
                    Rows(MY_ROWS).DELETE
                End If
                GoTo MY_NEXT
            End If
        Next MY_COLS
MY_NEXT:
    Next MY_ROWS
End Sub

But I think it works. You will need to play around with the colour number, depending on which green you are using.
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,628
Members
449,240
Latest member
lynnfromHGT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top