Deleteing cells

G

Guest

Can someone help. this is what I have so far...

Sub deleting_cells()

Columns("A:A").Select
Selection.Find(What:="Quantity", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(4, 0).Select
ActiveCell.Offset.End(xlToRight).Select
ActiveCell.Offset(0, -6).Range("A1").Select

' From this point I want to delete every cell to the left of this active
cell minus 1 (essentially the cell in column A) I have read through dozens of
posts, but can't seam to figure it out.
After deleteing these cells, I want to drop down to the next row, move to
the last to the right and continue deleting info as needed via a loop.

this is probably very easy, but I am new to the whole vba world.

Thanks
Peter
 
G

Guest

I'm lost. In simple language can you explain what it is you want. I am
guessing here but are you looking to find all instances of "quantity" in
Column A and then delete some of the info from those lines??? Guessing again
but did you want to delete all of the cells except the right most cell??? Did
you want to leave the word quantity or did you want to get rid of that also???
 
G

Guest

Sorry for the confusion Jim,

Finding Quantity is just my starting point. There is information above that
point I want to keep. I offset 4 cells down and all the way to the right,
Because the information I want to keep is always located in cell "A?" and in
the last 6 cells of any row under Quantity. The info I want to delect can be
a range of 3 to 23 cells long. Hence the reason I find the end of the data
row and offset back 6 cells to select my true starting point to loop through
and delete unwanted cells.

Does that help?
 
G

Guest

So if I find Quantity in Cell A10 then I go down 4 rows to A14. The last
populated cell in row 14 is in column K for example so K14. You want to
delete cells A14 through E14. Once that is done then go down to the next row
and evealute that row (15). If the last populted cell in row 15 is J15 then
delete A15:D15. How long does this process continue. Assuming I have it
right...
 
G

Guest

This is correct. except please keep the data in cell A. this should continue
until no data is found in a row.

Thanks
Peter
 
G

Guest

Give this a whirl...

Sub DeleteStuff()
Dim rngFound As Range
Dim rngToSearch As Range
Dim rng As Range
Dim rngToDelete As Range

Set rngFound = Columns("A").Find(What:="Quantity", _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Quantity was not found"
Else
Set rngToSearch = Range(rngFound.Offset(4, 0), _
rngFound.Offset(4, 0).End(xlDown))
For Each rng In rngToSearch
Set rngToDelete = Cells(rng.Row, Columns.Count).End(xlToLeft)
If rngToDelete.Column > 7 Then
Range(rng.Offset(0, 1), rngToDelete.Offset(0,
-6)).ClearContents
End If
Next rng
End If

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