How to create macro that deletes a row under these criteria?

Hello,

I need a macro that would delete all rows if these two criteria are met:

  • a cell in D column has a value equal to 5
  • a cell in H column is blank

I would be grateful for any help on this.

Hi

For example (work for the active sheet):

sub DeleteRows()

dim oSheet as object
dim oCellCursor as object, oCellRangeAddress as object, oCell as object
dim lRowNumber as long, lEndRow as long

oSheet = thiscomponent.currentController.activesheet
oCellCursor = oSheet.createCursor()

' Find the last used row '

oCellCursor.gotoEndOfUsedArea(True)
oCellRangeAddress = oCellCursor.getRangeAddress()
lEndRow = oCellRangeAddress.EndRow

'from the bottom to the top, one row at a time '

for lRowNumber  = lEndRow to 1 step -1
'	if cell in col D = 5 '
	oCell = oSheet.getCellByPosition(3, lRowNumber)
	if oCell.value = 5 then

'	if cell in col H = empty '    	
		oCell = oSheet.getCellByPosition(7, lRowNumber)
		if oCell.Type = com.sun.star.table.CellContentType.EMPTY then
			oSheet.rows.removeByIndex(lRowNumber, 1)
		end if
	end if	
next lRowNumber  

print "done"

end sub

[EDIT] I remind you that you can do this without macro with a simple standard filter to select the lines then right click on the line header to remove them…

Regards

Many thanks!
(Actually, I need this as a part of another macro that I have already created. A filter would require the additional manual work)