Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub MoveAndClearBlackCellsUp()
- Dim rng As Range
- Dim cell As Range
- ' Define the range to search within (adjust Sheet1 to your sheet name if different)
- Set rng = ThisWorkbook.Sheets("Sheet1").UsedRange
- For Each cell In rng
- If cell.Interior.Color = RGB(0, 0, 0) Then
- If cell.Row > 1 Then
- cell.Interior.ColorIndex = x1None
- cell.Offset(-1, 0).Interior.Color = RGB(0, 0, 0)
- cell.ClearContents
- Exit For
- End If
- End If
- Next cell
- End Sub
- Sub MoveAndClearBlackCellsDown()
- Dim rng As Range
- Dim cell As Range
- Set rng = ThisWorkbook.Sheets("Sheet1").UsedRange
- For Each cell In rng
- If cell.Interior.Color = RGB(0, 0, 0) Then
- If cell.Row > 1 Then
- cell.Interior.ColorIndex = x1None
- cell.Offset(1, 0).Interior.Color = RGB(0, 0, 0)
- cell.ClearContents
- Exit For
- End If
- End If
- Next cell
- End Sub
- Sub MoveAndClearBlackCellsLeft()
- Dim rng As Range
- Dim cell As Range
- Set rng = ThisWorkbook.Sheets("Sheet1").UsedRange
- For Each cell In rng
- If cell.Interior.Color = RGB(0, 0, 0) Then
- If cell.column > 1 Then
- cell.Interior.ColorIndex = x1None
- cell.Offset(0, 1).Interior.Color = RGB(0, 0, 0)
- cell.ClearContents
- Exit For
- End If
- End If
- Next cell
- End Sub
- Sub MoveAndClearBlackCellsRight()
- Dim rng As Range
- Dim cell As Range
- Set rng = ThisWorkbook.Sheets("Sheet1").UsedRange
- For Each cell In rng
- If cell.Interior.Color = RGB(0, 0, 0) Then
- If cell.column > 1 Then
- cell.Interior.ColorIndex = x1None
- cell.Offset(0, -1).Interior.Color = RGB(0, 0, 0)
- cell.ClearContents
- Exit For
- End If
- End If
- Next cell
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement