PDA

View Full Version : VBA Assistance - Highlighting and Deleting based on another cell value.



joeltider
03-10-2016, 10:35 AM
Good Morning here is my current setup...

In a sheet named "Copy" Cell O1 contains a number which will change each time.

In a sheet named "Paste" there are rows sorted based on another macro.

My question, how do I write a macro to highlight rows in "Paste" based on the number showing in sheet "Copy" Cell O1? When highlighted I want to delete the information. I have done this before and now im stuck for some reason.

Thanks!

joeltider
03-10-2016, 12:20 PM
Ok change of plans, eliminating the cell value, now moving to just highlight data based on cell values. unfortunate the code below finds where the data ends, but it misses where data begins on B2.



Dim nRow As Long
Dim nStart As Long, nEnd As Long
' Figure out where the "Yes" data starts.
For nRow = 1 To 65536
If Range("B" & nRow).Value = "Yes" Then
nStart = nRow
Exit For
End If
Next nRow
' Figure out where the "Yes" data ends.
For nRow = nStart To 65536
If Range("B" & nRow).Value <> "Yes" Then
nEnd = nRow
Exit For
End If
Next nRow
nEnd = nEnd - 1
Range("B2" & nStart & ":K" & nEnd).Select