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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Rows in Excel

Status
Not open for further replies.

darude

Programmer
Jun 23, 2003
138
US
Hi All,
I am working on an Excel project. I download data from a state agency, store it in multiple sheets in the same workbook and manually reformat each sheet. I want to automatically:

delete the first 3 rows

delete columns A, B and C

insert a top row with titles studentid, score

I have looked around, but haven't found my answer yet. Thank you in advance.
 
Go to Tools > Macro > Record New Macro.

Do what you want.

Observe the code that was generated using the VBEditor ([Alt]+[F11]).

Post the code you create if you have any questions about how to tweak/change/optimize it.

[tt][blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ 181-2886 before posting.
 
Okay, here's the macro it created. I want to do this for every sheet I add to the workbook instead having to run the macro for each sheet. There could be 28 sheets in this workbook.

Rows("1:3").Select
Selection.Delete Shift:=xlUp
Columns("A:C").Select
Selection.Delete Shift:=xlToLeft
Columns("B:AQ").Select
Selection.Delete Shift:=xlToLeft
Columns("C:C").Select
Selection.Delete Shift:=xlToLeft
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Range("A1").Select
ActiveCell.FormulaR1C1 = "Score"
Range("B1").Select
ActiveCell.FormulaR1C1 = "StudentID"
Rows("2:3").Select
Selection.Delete Shift:=xlUp
 


Hi,
Code:
sub DeleteStuff()
  dim ws as worksheet
  for each ws in worksheets
    With ws
        .Rows("1:3").Delete Shift:=xlUp
        .Columns("A:C").Delete Shift:=xlToLeft
        .Columns("B:AQ").Delete Shift:=xlToLeft
        .Columns("C:C").Delete Shift:=xlToLeft
        .Rows("1:1").Insert Shift:=xlDown
        .Range("A1").FormulaR1C1 = "Score"
        .Range("B1").FormulaR1C1 = "StudentID"
        .Rows("2:3").Delete Shift:=xlUp
    End With
  next
end sub


Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top