Delete rows at the same time from selected worksheets

G

Guest

I tried to write VB code that selects four worksheets, and then deletes rows
3 to 4, but what happens is that it only deletes the data from the active
worksheet. If we use VB code, do we just have the option to perform the
deletion one worksheet at a time, or is there a way to do the deletion on all
four worksheets at the same time?

Thank you.
 
N

Norman Jones

Hi Filo,

I think that it would be nevessary to cycle throrgh the
sheets of interest.

For example, try something like:

'=============>>
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet

Set WB = ActiveWorkbook '<<===== CHANGE

For Each SH In WB.Worksheets
SH.Rows("3:4").Delete
Next SH
End Sub
'<<=============
 
N

Norman Jones

I think that it would be nevessary to cycle throrgh the
sheets of interest.

==>

I think that it would be necessary to cycle through the
sheets of interest.
 
D

Don Guillett

the macro recorder is your friend
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 5/5/2007 by Donald B. Guillett
'

'
Sheets(Array("Sheet2", "Sheet3")).Select
Sheets("Sheet3").Activate
Rows("3:4").Select
Selection.Delete Shift:=xlUp
Sheets("Sheet1").Select
End Sub
but a for/next might even be better

for each ws in worksheets
if ws.name <> "keepthisone" then ws.rows("3:4").delete
next ws
 

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