karl_learnvba
New Member
- Joined
- Oct 10, 2019
- Messages
- 12
- Office Version
- 365
- Platform
- Windows
Hello all, Just diving into VBA - Thank you in advance for your help.
I have a worksheet which from which I have associated macros to buttons to launch a series of VBA macros - Called "Process". I would like to run all macros from the "process" tab
I have another worksheet called "Working Dataset" where I am looking to clear the content of the cells, below the header.
The problem that I am experiencing is that the VBA code is clearing the content from the "Process" worksheet when the code is run from the button, rather than the "Working Dataset" worksheet.
Here is the code that I developed (i know it is basic!!) - what am I doing wrong ?
I have a worksheet which from which I have associated macros to buttons to launch a series of VBA macros - Called "Process". I would like to run all macros from the "process" tab
I have another worksheet called "Working Dataset" where I am looking to clear the content of the cells, below the header.
The problem that I am experiencing is that the VBA code is clearing the content from the "Process" worksheet when the code is run from the button, rather than the "Working Dataset" worksheet.
Here is the code that I developed (i know it is basic!!) - what am I doing wrong ?
VBA Code:
Sub YY()
Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws, ws1 As Worksheets: Set ws = wb.Worksheets("Working Dataset")
'Clear the contents of the columns below the header
ws.Range(Cells(2, 1), Cells(Rows.Count, 1)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 2)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 3)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 4)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 5)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 6)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 7)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 8)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 9)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 10)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 11)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 12)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 13)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 14)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 15)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 16)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 17)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 18)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 19)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 20)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 21)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 22)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 23)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 24)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 25)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 26)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 27)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 28)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 29)).ClearContents
ws.Range(Cells(2, 1), Cells(Rows.Count, 30)).ClearContents
'This routine copies the SI data into the working data tab
Set ws1 = wb.Worksheets("SI Data")
ws1.Range("SI_Data_Import").Copy
ws.Range("A2").PasteSpecial xlPasteValues
ws.Range("A:A").NumberFormat = "General"
ws.Range("C:C").NumberFormat = "General"
ws.Range("Q:W").NumberFormat = "#,##0"
ws.Range("Z:AC").NumberFormat = "#,##0"
ws.Range("AD:AD").NumberFormat = "0%"
ws.Range("AE:AG").NumberFormat = "#,##0"
ws.Range("AN:AN").NumberFormat = "General"
ws.Range("AQ:AQ").NumberFormat = "General"
End Sub