Hello again.
Well its completely confused me.
This code provided kindly by Rick Rothstein works a treat if it is in the sheet where the data is, however i was trying to modifiy it so that it worked from a seperate sheet via a command button. The coded Rick provided is
Sub DeleteZeroSums()
Dim LastRow As Long, LastCol As Long
Range("D146:DS146").Value = Range("D145:DS145").Value
Range("DU17:DU144").Value = Range("DT17:DT144").Value
Range("D146:DS146").Replace 0, "=0", xlWhole
Range("DU17:DU144").Replace 0, "=0", xlWhole
On Error Resume Next
Range("DU17:DU144").SpecialCells(xlCellTypeFormulas).EntireRow.Delete
LastRow = Cells(Rows.Count, "DT").End(xlUp).Row + 1
Range("D" & LastRow & ":DS" & LastRow).SpecialCells(xlCellTypeFormulas).EntireColumn.Delete
LastCol = Cells(LastRow, Columns.Count).End(xlToLeft).Column
Rows(LastRow).Clear
Columns(LastCol + 2).Clear
End Sub
I have set up 2 command buttons on sheet 1 and this is the code i am trying with out success. Any ideas please why it will not work like this?
Sub CommandButton1_Click()
Application.ScreenUpdating = False
Workbooks.Open Filename:=ThisWorkbook.Path & "\base data.xls"
Sheets("base data 1").Range("a1:dt170").Copy
Windows("file control.xls").Activate
Sheets.Add.Name = ("base data sheet1")
Sheets("base data sheet1").Range("a1").PasteSpecial Paste:=xlPasteAll
End Sub
Private Sub CommandButton2_Click()
Dim LastRow As Long, LastCol As Long
'Sheets("base data sheet1").Select
Sheets("base data sheet1").Range("D146:DS146").Value = Range("D145:DS145").Value
Sheets("base data sheet1").Range("DU17:DU144").Value = Range("DT17:DT144").Value
Sheets("base data sheet1").Range("D146:DS146").Replace 0, "=0", xlWhole
Sheets("base data sheet1g").Range("DU17:DU144").Replace 0, "=0", xlWhole
On Error Resume Next
Sheets("base data sheet1").Range("DU17:DU144").SpecialCells(xlCellTypeFormulas).EntireRow.Delete
LastRow = Cells(Rows.Count, "DT").End(xlUp).Row + 1
Sheets("base data sheet1").Range("D" & LastRow & ":DS" & LastRow).SpecialCells(xlCellTypeFormulas).EntireColumn.Delete
LastCol = Cells(LastRow, Columns.Count).End(xlToLeft).Column
Rows(LastRow).Clear
Columns(LastCol + 2).Clear
Sheets("base data sheet1").Range("D16:DS16").FormulaR1C1 = "=AVERAGE(R[-2]C:R[-1]C)"
Sheets("base data sheet1").Range("c17:c144").FormulaR1C1 = "=AVERAGE(RC[-2]:RC[-1])"
End Sub
Well its completely confused me.
This code provided kindly by Rick Rothstein works a treat if it is in the sheet where the data is, however i was trying to modifiy it so that it worked from a seperate sheet via a command button. The coded Rick provided is
Sub DeleteZeroSums()
Dim LastRow As Long, LastCol As Long
Range("D146:DS146").Value = Range("D145:DS145").Value
Range("DU17:DU144").Value = Range("DT17:DT144").Value
Range("D146:DS146").Replace 0, "=0", xlWhole
Range("DU17:DU144").Replace 0, "=0", xlWhole
On Error Resume Next
Range("DU17:DU144").SpecialCells(xlCellTypeFormulas).EntireRow.Delete
LastRow = Cells(Rows.Count, "DT").End(xlUp).Row + 1
Range("D" & LastRow & ":DS" & LastRow).SpecialCells(xlCellTypeFormulas).EntireColumn.Delete
LastCol = Cells(LastRow, Columns.Count).End(xlToLeft).Column
Rows(LastRow).Clear
Columns(LastCol + 2).Clear
End Sub
I have set up 2 command buttons on sheet 1 and this is the code i am trying with out success. Any ideas please why it will not work like this?
Sub CommandButton1_Click()
Application.ScreenUpdating = False
Workbooks.Open Filename:=ThisWorkbook.Path & "\base data.xls"
Sheets("base data 1").Range("a1:dt170").Copy
Windows("file control.xls").Activate
Sheets.Add.Name = ("base data sheet1")
Sheets("base data sheet1").Range("a1").PasteSpecial Paste:=xlPasteAll
End Sub
Private Sub CommandButton2_Click()
Dim LastRow As Long, LastCol As Long
'Sheets("base data sheet1").Select
Sheets("base data sheet1").Range("D146:DS146").Value = Range("D145:DS145").Value
Sheets("base data sheet1").Range("DU17:DU144").Value = Range("DT17:DT144").Value
Sheets("base data sheet1").Range("D146:DS146").Replace 0, "=0", xlWhole
Sheets("base data sheet1g").Range("DU17:DU144").Replace 0, "=0", xlWhole
On Error Resume Next
Sheets("base data sheet1").Range("DU17:DU144").SpecialCells(xlCellTypeFormulas).EntireRow.Delete
LastRow = Cells(Rows.Count, "DT").End(xlUp).Row + 1
Sheets("base data sheet1").Range("D" & LastRow & ":DS" & LastRow).SpecialCells(xlCellTypeFormulas).EntireColumn.Delete
LastCol = Cells(LastRow, Columns.Count).End(xlToLeft).Column
Rows(LastRow).Clear
Columns(LastCol + 2).Clear
Sheets("base data sheet1").Range("D16:DS16").FormulaR1C1 = "=AVERAGE(R[-2]C:R[-1]C)"
Sheets("base data sheet1").Range("c17:c144").FormulaR1C1 = "=AVERAGE(RC[-2]:RC[-1])"
End Sub