wild card *

T

transferxxx

My macro below is not working properly:

Sub Deletedepo()


With ActiveSheet
..DisplayPageBreaks = False
StartRow = 1
EndRow = .Cells(.Rows.Count, "C").End(xlUp).Row
For Lrow = EndRow To StartRow Step -1

If .Cells(Lrow, "C").Value = "CASH DEPOSIT *" Then

..Rows(Lrow).Delete
End If
Next
End With
End Sub

I would like to delete all rows with cells in column c containing e.g
Cash deposit GBP1000
Cash deposit Euro 50
But the wild card * is not working - can someone pls correct my macro
Thxs
 
F

Faisal...

Try this:

Sub Deletedepo()

With ActiveSheet
..DisplayPageBreaks = False
StartRow = 1
EndRow = .Cells(.Rows.Count, "C").End(xlUp).Row
For Lrow = EndRow To StartRow Step -1

strVal=.Cells(Lrow, "C").Value
If LEFT(strVal,12) = "CASH DEPOSIT" Then

..Rows(Lrow).Delete
End If
Next
End With
End Sub
 
T

transferxxx

thxs it works - but i don't understand why * can't make it - can someone
explain it to me thxs
 
D

Dave Peterson

This is looking for an asterisk--not a wildcard:
If .Cells(Lrow, "C").Value = "CASH DEPOSIT *" Then
That's the way "=" works.

You may want to look at VBA's help for Like (where you can use wildcards).
 
T

transferxxx

Sub insert()
Dim r As Range
Dim rd As Range
Set r = Range("C8")
Do While Not IsEmpty(r)
Set rd = r.Offset(1, 0)
If r.Offset(0, -1) = "CASH DEPOSIT" Then
r.insert Shift:=xlToRight
End If
Set r = rd
Loop
End Sub

i have tried to modify the above code as per below but it's not working -
can some one help.

Sub insert()
Dim r As Range
Dim rd As Range
Set r = Range("c8")
Do While Not IsEmpty(r)
Set rd = r.Offset(1, 0)
strVal = r.Offset(0, -1).Value
If Left(strVal, 12) = "CASH DEPOSIT" Then
r.insert Shift:=xlToRight
End If
Set r = rd
Loop
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top