delete columns based on information in another column

  • Thread starter Thread starter NewBee
  • Start date Start date
N

NewBee

I am trying to delete columns 'A' and 'B' based on if there is some data in
column 'C'. I am trying to write a macro to accomplish this. Any help is
appreciated.
 
Hello,

Think logically:

if there is something in column C, must delete column A
.... so, delete column A
Now, the old column B has become column A
.... so, again, delete column A


Hope this helps !
 
Hi,

You don't give too much information so use this cautiously becuase it will
cler row A & B if it finds anything in row C. Right click the sheet tab, view
code and paste it in

Sub stance()
Dim myrange, copyrange As Range
Lastrow = Cells(Cells.Rows.Count, "C").End(xlUp).Row
Set myrange = Range("C1:C" & Lastrow)
For Each c In myrange
If c.Value <> "" Then 'Change to a particular value
If copyrange Is Nothing Then
Set copyrange = c.Offset(0, -2).Resize(, 2)
Else
Set copyrange = Union(copyrange, c.Offset(0, -2).Resize(, 2))
End If
End If
Next
If Not copyrange Is Nothing Then
copyrange.ClearContents
End If
End Sub


Mike
 
Mike I want to take the time to thank you for the solution you have provided
to me. I will execute it today and will provide you with feedback. I
appreciate the fact that you have taken the time to respond to my query
 

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

Back
Top