I want to delete the n% of the cells from the sheet1,sheet2,sheet3,sheet4. The percentage will be given in the sheet name as raw. For example in raw sheet in E19 its given 10%, so in every sheet S1,S2,S3,S4 it should delete the total of 10% of the rows of data. (example: sheet 1 have 100 rows with data so as per 10% it should delete the 10 rows from 100 rows and similarly for other sheets as well. I have researched alot but did not get anything relevant to this.
Asked
Active
Viewed 94 times
1 Answers
2
To delete the first x percent of the lines you can do it like this:
s.Range(s.Cells(1, 1), s.Cells(s.UsedRange.Rows.Count * Range("Percentage").Value, 1)).EntireRow.Delete
Where the range ("Percentage") is the cell where your percentages are given
To get it for all sheets, you just need a loop to repeat that:
Sub deleteFirstPercentageOfRows()
Dim s As Worksheet
For Each s In ThisWorkbook.Sheets
If s.Name <> "raw" Then
s.Range(s.Cells(1, 1), s.Cells(s.UsedRange.Rows.Count * Range("Percentage").Value, 1)).EntireRow.Delete
End If
Next s
End Sub