netrixuser
Board Regular
- Joined
- Jan 21, 2019
- Messages
- 77
- Office Version
- 365
- Platform
- Windows
Hi All, I'd appreciate your help in approaching my current issue - sort of Userform related initially but my lack of knowledge has pushed me to the vba route.
Trying to summarise:
I have a spreadsheet with data in columns A through P and Rows 4 to 26.
Following a Youtube tutorial I have managed to construct a userform that populates the sheet (one row of data at a time) it will populate the data into the next free row of the sheet each time. I also managed to get an Edit option whereby the userform pulls the data from the sheet and writes it back the changes back to the original row of data in the sheet.
My problem is that some of the rows will need to be deleted before others and those deleted rows could be anywhere in the sheet. Ideally I would like a option in the userform to pull back data from the sheet and delete it from there but I had no clue on how to go about this.
My Userform it is written such that it references an "anchor point" at the top of the data in column A to move down and across, and uses the result of a CountA for cells A5:A26 to know where the next blank row is [CountA plus 1]
So, with my limited knowledge, I added a column in the sheet (Column Y) for the user to enter a Y in the corresponding row that is to be deleted, and then call a Macro via a button on the sheet to delete those rows. I "borrowed" the code below from t'internet to move down and delete the entire row if there is a Y in the column.
But I need the overall number or rows to be constant - ie to count the rows deleted and insert them back - any ideas please on how to achieve this ?
Many thanks for your time.
Trying to summarise:
I have a spreadsheet with data in columns A through P and Rows 4 to 26.
Following a Youtube tutorial I have managed to construct a userform that populates the sheet (one row of data at a time) it will populate the data into the next free row of the sheet each time. I also managed to get an Edit option whereby the userform pulls the data from the sheet and writes it back the changes back to the original row of data in the sheet.
My problem is that some of the rows will need to be deleted before others and those deleted rows could be anywhere in the sheet. Ideally I would like a option in the userform to pull back data from the sheet and delete it from there but I had no clue on how to go about this.
My Userform it is written such that it references an "anchor point" at the top of the data in column A to move down and across, and uses the result of a CountA for cells A5:A26 to know where the next blank row is [CountA plus 1]
So, with my limited knowledge, I added a column in the sheet (Column Y) for the user to enter a Y in the corresponding row that is to be deleted, and then call a Macro via a button on the sheet to delete those rows. I "borrowed" the code below from t'internet to move down and delete the entire row if there is a Y in the column.
But I need the overall number or rows to be constant - ie to count the rows deleted and insert them back - any ideas please on how to achieve this ?
Many thanks for your time.
VBA Code:
Sub DeleteCells2()
Dim rng As Range
Dim i As Integer, counter As Integer
Set rng = Range("P5:P26")
i = 1
For counter = 1 To rng.Rows.Count
If rng.Cells(i) = "Y" Then
rng.Cells(i).EntireRow.Delete
Else
i = i + 1
End If
Next
End Sub