VBA If and loop

CoolMacro

New Member
Joined
Sep 9, 2013
Messages
16
Hi!
I'm trying to make a macro that searches a date in cell A1 and a combination of two criteria in cell D1, then i need delete entire row, how can I do this?
Follow the example: A B C D
Date ClientCountHistoric
01/08/2013 XXXXX1,019.00YYYYYY - 02/07/2013
01/08/2013 XXXXX 1,019.00YYYYYY - 29/07/2013
01/08/2013 XXXXX1,019.00WWWW
05/08/2013 XXXXX1,019.00WWWW
01/08/2013 XXXXX 1,019.00YYYYYY - 31/07/2013
01/08/2013 XXXXX1,019.00WWWW
01/08/2013 XXXXX1,019.00WWWW

<tbody>
</tbody>



And the spreadsheet looks like this:
A B C D
Date ClientCountHistoric
01/08/2013 XXXXX1,019.00YYYYYY - 02/07/2013
01/08/2013 XXXXX1,019.00WWWW
05/08/2013 XXXXX1,019.00WWWW
01/08/2013 XXXXX1,019.00WWWW
01/08/2013 XXXXX1,019.00WWWW

<tbody>
</tbody>
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I tryed this
Sub TestePeriodoCCIf()
'
'


Application.ScreenUpdating = False

Sheets("cc").Select
Dim i As Integer
Dim n As Integer

i = 1
n = Sheets("cc").Range("A1048576").End(xlUp).Row


Do While i < n
If Trim(Sheets("cc").Range("A" & i).Value) = "*" & Sheets("Início").Range("A1").Value & "*" Then
If Trim(Sheets("cc").Range("D" & i).Value) = "*Preg*" And ("*" & Sheets("Início").Range("A2").Value & "*" Or "*" & Sheets("Início").Range("A2").Value & "*") Then
Rows(i & ":" & i).Select
Selection.Delete Shift:=xlUp

End If
n = n - 1
Else
i = i + 1
End If
Loop


Aplication.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,769
Messages
6,126,787
Members
449,336
Latest member
p17tootie

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top