simple if then statement - macro

midwestjill

New Member
Joined
Jan 17, 2005
Messages
7
Please help!

I just need a simple excel VB macro that will do the following:

If a1=b1 then delete c1
If a2=b2 then delete c2

This needs to loop through the rest of the data on one sheet.

Thanks in advance,
Jill Swenson
Fargo, ND
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi Jill, welcome to the board!!


What column will be the longest? We can set the last row to equal the last contiguous row in a specific column and loop through rows 1 through rows last row. Also, what will be held in these columns (A, B & C)?
 
Upvote 0
I assume no spaces between data.

sub seekand destoy()
range("A1").select
do until activecell.text = ""
if activecell.text = activecell.offset(0,1).text then activcell.offset(0,3).clearcontents
activecell.offset(1,0).select
loop
end sub
 
Upvote 0
If you use column A to set the last row, i.e. the last row of column A with data populated in it, you can use something like this ...



<font face=Tahoma New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN>

<SPAN style="color:#00007F">Sub</SPAN> CheckColsAandB()
    <SPAN style="color:#00007F">Dim</SPAN> lastRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>
    lastRow = Sheets("Sheet1").Range("A65536").End(xlUp).Row
    <SPAN style="color:#00007F">For</SPAN> i = 1 <SPAN style="color:#00007F">To</SPAN> lastRow
        <SPAN style="color:#00007F">If</SPAN> Sheets("Sheet1").Range("A" & i) = Sheets("Sheet1").Range("B" & i) <SPAN style="color:#00007F">Then</SPAN>
            Sheets("Sheet1").Range("C" & i).ClearContents
        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
    <SPAN style="color:#00007F">Next</SPAN> i
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
 
Upvote 0

Forum statistics

Threads
1,203,435
Messages
6,055,366
Members
444,781
Latest member
rishivar

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