Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import text & automate task in Excel

Status
Not open for further replies.

ashows

MIS
May 10, 2002
25
US
I've imported a text file into Excel but I don't need every row of data. I've started on a macro to automate the tasks of deleting the extra rows, but I don't know how to make it loop through a certain set of events. I need it to check the active cell to see if it contains text. If it does, then it needs to do the following:
*Move down one row
*Delete 7 rows
*Move down 5 rows
*Delete 10 rows

Thanks in advance!
 
Sub Macro1()
'*if active cell contains text
If Len(ActiveCell.Text) > 0 Then

'*Move down one row (active cell?)
' this instruction will overwrite down cell!!!
ActiveCell.Cut Destination:=ActiveCell.Offset(1, 0)
ActiveCell.Offset(1, 0).Activate

'*Delete 7 rows (which 7 rows?)
' delete next 7 rows
ActiveCell.Offset(1, 0).Resize(7, 1).EntireRow.Delete

'*Move down 5 rows (what to move?, active cell?)
ActiveCell.Cut Destination:=ActiveCell.Offset(5, 0)
ActiveCell.Offset(5, 0).Activate

'*Delete 10 rows (which 10 rows?)
' delete next 10 rows
ActiveCell.Offset(1, 0).Resize(10, 1).EntireRow.Delete
End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top