Следующее возьмет вашу текущую ячейку и удалит все, кроме диагоналей. Выберите верхнюю левую ячейку, и все диагонали останутся ... Но мне нравится ответ KazJaw.
Sub go_sub()
'get the range from current cell to the end
Lastrow = ActiveSheet.Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
Lastcol = ActiveSheet.Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column
Set myRange = ActiveSheet.Range(Selection, ActiveSheet.Cells(Lastrow, Lastcol))
'set the next cell to keep as current one
Set Nextcell = selection
'cycle throug all cells in the range
For Each cel In myRange
'if the cell is to be kept?
if cel.address = nextcell.address then
'Reset the next cell to save BUT DONE CLEAR THECURRENT CELL
set Nextcell = Nextcell.offset(1,1)
Else
'clear current cell if not to be saved
Cel.clearcontents
End if
Next
End Sub
До:
После:
Может 'O' быть где-нибудь или будет всегда, как вы показали выше? –
@SiddharthRout Я хочу сохранить диагональ и удалить остальные. – ihatetoregister
Всегда блок 4x4 или нет? Если это так, просто запишите себя ... – AakashM