
Active Member

December 20, 2019

Hello!
When I select any particular entire row and run vba then it should delete
data in that row from B,C,D,E then J,K and S,T,U,V only. This is for delete.
If entire row is not selected then vba first inform to select the row.
Same system for Cut and Paste
Tried to search a lot on the net but did not get any answer.
If anyone can help me
Thanks


Trusted Members

December 20, 2019

Assuming you want to just delete the contents of the cells?
Sub DeleteSelectedInRow()
Dim r As Long
Dim ColsCount As Long
ColsCount = Selection.Columns.Count
Debug.Print ColsCount
If ColsCount <> 16384 Then
MsgBox "Please select entire row before continuing", vbCritical
Exit Sub
Else
End If
r = ActiveCell.Row
Range("b" & r).ClearContents
Range("c" & r).ClearContents
Range("d" & r).ClearContents
Range("e" & r).ClearContents
Range("j" & r).ClearContents
Range("k" & r).ClearContents
Range("s" & r).ClearContents
Range("t" & r).ClearContents
Range("u" & r).ClearContents
End Sub
Not sure where you want to paste for the copy and paste one


Trusted Members

December 20, 2019

Okay, so the below code will copy the cells from the selected row as ask you to type in a destination row number
Sub CutNPasteSelectedRow()
Dim cRow As Long
Dim ColsCount As Long
Dim pRow As Long
ColsCount = Selection.Columns.Count
If ColsCount <> 16384 Then
MsgBox "Please select entire row before continuing", vbCritical
Exit Sub
Else
End If
cRow = ActiveCell.Row
pRow = InputBox("Please select the row to paste the results", vbCritical)
Range("b" & cRow).Cut Range("b" & pRow)
Range("c" & cRow).Cut Range("c" & pRow)
Range("d" & cRow).Cut Range("d" & pRow)
Range("e" & cRow).Cut Range("e" & pRow)
Range("j" & cRow).Cut Range("j" & pRow)
Range("k" & cRow).Cut Range("k" & pRow)
Range("s" & cRow).Cut Range("s" & pRow)
Range("t" & cRow).Cut Range("t" & pRow)
Range("u" & cRow).Cut Range("u" & pRow)
End Sub

Answers Post

Active Member

December 20, 2019

Thanks a lot Purfleet. Saved a lot of time because of the code.
Only in case of Delete code can it be made for multiple selection.
However even this is ok.
Since the querry is solved do i need to tick mark the Useful Answer.
Thanks Again and Merry Christmas to you and all the other members.


Trusted Members

December 20, 2019


Active Member

December 20, 2019

Hello and sorry for delay in reply. Was on leave.
Can this topic be slightly extended more to make the working code more flexible.
As I started working on the above code I came across these issues.
The Delete part where pressing ctrl key I select multiple rows in a sheet and run the code.
The Cut & Paste is working fine since it is required in the same sheet at present.
But if I want to cut from the existing sheet and paste in the row in another sheet named
GENERAL. A separate code if want paste in another sheet.
Thanks
Happy New Year.
1 Guest(s)
