Thanx, problem is solved now
Hello again,
I tried what Celia suggested. And after letting away the last row and the help of a friend which programmed VB for years (what I didn´t knew before) the macro is working how it should.
So I want to thank everyone for his/her quick and qualified help.
Please go on like this because that´s what the internet makes so useful thanks again,
Christian.
Would it actually be a string like closed or actually = close
Hi David,
the string is exactly "closed".
Greetings,
Christian.
try this
For x = 1 To Range("E1").End(xlDown).Row
If Cells(5, x) = "close" Then
Rows(x & ":" & x).Delete shift:=xlUp
End If
Next x
at first a short description of my problem: I import some textfiles into a sheet, look if any of the cells in column E contain the string "close" and delete the related rows completely. Due to the fact that i already have macro, I want to integrate the functionality described above. And my problem now is that I am searching for about three weeks on the web for a solution....and now I am here=) I have located the area in which I have to add the code I need but don´t know the Excel-Syntax so I noticed it instead in "Pseudocode": while(row <= lastrow) { if cell(row/column E) contains string "close" { delete whole row; row = row + 1; } else { row = row + 1; } } Ok, that´s it. If someone is able to help me I would be more than happy because I am totally desperated. Many thanks for your help, Christian.
:
When deleting rows in a loop, it is better to go from the last to the first.
When looping from the first to the last, the next row is "skipped" each time a row is deleted. In the present example, this means that if there are two consecutive rows containing "close", the second one will not be deleted.
The following loops from the last to the first :-
For x = Range("E1").End(xlDown).Row To 1 Step -1
If Cells(x, 5) = "close" Then
Rows(x).Delete shift:=xlUp
End If
Next x
End Sub