Macro not deleting zero values from new sheet.

ghrek

Active Member
Joined
Jul 29, 2005
Messages
427
Hi

I have this macro and it copies and pastes to the new sheet but does not vopy new values into column Y and delete the zero values from the new sheet.

Any Ideas?
VBA Code:
Option Explicit

Sub TransferData()
Dim lngLastRow As Long
Dim lngRow As Long
Dim strSheetName As String
Dim wsSource As Worksheet

lngLastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Set wsSource = ActiveSheet

With Application
    .EnableEvents = False
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With

strSheetName = InputBox("Please enter the name of the new worksheet", "Transfer Data")
If StrPtr(strSheetName) = 0 Then
    MsgBox "No worksheet name entered"
    Exit Sub
End If
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi ghrek,

the code you published is sort of an unfinished symphony - it's incomplete.

Ciao,
Holger
 
Upvote 0
Hi ghrek,

maybe start with showing the complete code? There is no code dealing with deleting any values...

Holger
 
Upvote 0
Apologies... Here goes
VBA Code:
Option Explicit

Sub TransferData()
Dim lngLastRow As Long
Dim lngRow As Long
Dim strSheetName As String
Dim wsSource As Worksheet

lngLastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Set wsSource = ActiveSheet

With Application
    .EnableEvents = False
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With

strSheetName = InputBox("Please enter the name of the new worksheet", "Transfer Data")
If StrPtr(strSheetName) = 0 Then
    MsgBox "No worksheet name entered"
    Exit Sub
End If

Sheets.Add(After:=Sheets(Sheets.Count)).Name = strSheetName
wsSource.Range("A1:Y" & lngLastRow).Copy
With ActiveSheet
    .Range("A1").PasteSpecial
    .Range("G10:Y" & lngLastRow).Clear
    For lngRow = lngLastRow To 1 Step -1
        If Not IsEmpty(.Cells(lngRow, "Y")) Then
            If .Cells(lngRow, "Y") = 0 Then
                .Cells(lngRow, "Y").EntireRow.Delete
            End If
        End If
    Next
End With

With Application
    .Calculation = xlCalculationAutomatic
    .EnableEvents = True
    .ScreenUpdating = True
End With


End Sub
 
Upvote 0
Hi ghrek,

if you apply the codeline

VBA Code:
    .Range("G10:Y" & lngLastRow).Clear

the loop for Column Y should be restricted to

VBA Code:
    For lngRow = 10 To 1 Step -1

I wonder why you use PasteSpecial as no XlPasteSpecialOperation-Enumeration is mentioned.

Holger
 
Upvote 0
Solution
Hi ghrek.

as Y10 is empty the loop should start with 9 instead of 10. On my testbook everything wokrs like I expect it to be but this might be due to the simple formulas I choose to test.

Holger
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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