VBA to delete rows with certain value before duplicating

shayalsamawi

New Member
Joined
Sep 9, 2021
Messages
16
Office Version
  1. 365
Platform
  1. Windows
Hi guys,

I have this VBA code:


Public Sub ShippingForecastMoveAlong()
Dim newName As String

On Error Resume Next
newName = InputBox("Please Enter New Period")


If newName <> "" Then
ActiveSheet.Copy After:=Worksheets(Sheets.Count)
On Error Resume Next
ActiveSheet.Name = newName
End If
End Sub


That duplicates the sheet into a new sheet (within the same workbook)

Before duplicating the sheet - I want any rows (starting column I row 8) with a "1" to be deleted.

I've attached a picture (users click end period and the sheet is duplicated without any rows that contain 1)

Can anybody help?

Thanks so much :)


1643883090155.png
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
The script looks for the number 1 in column i
Starting in Row (8)
And deletes any row with just the number 1 not 1284
VBA Code:
Sub Make_New_Sheet()
'Modified 2/4/2022  4:36:42 AM  EST
Application.ScreenUpdating = False
On Error GoTo M
Dim i As Long
Dim Lastrow As Long
Dim newName As String
Lastrow = Cells(Rows.Count, "I").End(xlUp).Row

For i = Lastrow To 8 Step -1
    If Cells(i, "I").Value = 1 Then Rows(i).Delete
Next
'Second part
newName = InputBox("Please Enter New Period")


If newName <> "" Then
ActiveSheet.Copy After:=Worksheets(Sheets.Count)
ActiveSheet.Name = newName
End If

Application.ScreenUpdating = True
Exit Sub
M:
MsgBox "We had a Problem"
Application.ScreenUpdating = True

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top