Move data to an empty row when deleting an entry

YingFa

Board Regular
Joined
Nov 4, 2019
Messages
63
I have the below code to delete an entry from different sheets. If the entry that is deleted is in between rows, then there will be a blanck space in the databases of the different sheets. Would it be possible to modify my code to move the data 1 row up into the the deleted /empty row in order to avoid having blank spaces/rows in between my data?

VBA Code:
Private Sub CommandButton1_Click()

'Update SAR
If Me.ComboBox1.Value = "" Then
MsgBox "SAR Can Not be Blank!", vbExclamation, "SAR"
Exit Sub
End If

SAR = Me.ComboBox1.Value
Sheets("Sheet1").Select

Dim rowSelect As Long
rowSelect = Me.ComboBox1.ListIndex + 6

Cells(rowSelect, 1) = ""
Cells(rowSelect, 2) = ""
Cells(rowSelect, 3) = ""
Cells(rowSelect, 4) = ""
Cells(rowSelect, 5) = ""
Cells(rowSelect, 6) = ""
Cells(rowSelect, 7) = ""
Cells(rowSelect, 8) = ""
Cells(rowSelect, 9) = ""
Cells(rowSelect, 10) = ""
Cells(rowSelect, 11) = ""
Cells(rowSelect, 12) = ""
Cells(rowSelect, 13) = ""
Cells(rowSelect, 14) = ""
Cells(rowSelect, 15) = ""
Cells(rowSelect, 16) = ""
Cells(rowSelect, 17) = ""
Cells(rowSelect, 18) = ""
Cells(rowSelect, 19) = ""
Cells(rowSelect, 20) = ""
Cells(rowSelect, 21) = ""
Cells(rowSelect, 22) = ""
Cells(rowSelect, 23) = ""

Sheets("Sheet2").Select

Cells(rowSelect, 1) = ""
Cells(rowSelect, 2) = ""
Cells(rowSelect, 3) = ""
Cells(rowSelect, 4) = ""
Cells(rowSelect, 5) = ""
Cells(rowSelect, 6) = ""
Cells(rowSelect, 7) = ""
Cells(rowSelect, 8) = ""
Cells(rowSelect, 9) = ""
Cells(rowSelect, 10) = ""
Cells(rowSelect, 11) = ""

Sheets("Sheet3").Select

Cells(rowSelect, 1) = ""
Cells(rowSelect, 2) = ""
Cells(rowSelect, 3) = ""
Cells(rowSelect, 4) = ""
Cells(rowSelect, 5) = ""
Cells(rowSelect, 6) = ""
Cells(rowSelect, 8) = ""
Cells(rowSelect, 9) = ""
Cells(rowSelect, 7) = ""
Cells(rowSelect, 11) = ""
Cells(rowSelect, 12) = ""
Cells(rowSelect, 13) = ""
Cells(rowSelect, 10) = ""
Cells(rowSelect, 15) = ""
Cells(rowSelect, 16) = ""
Cells(rowSelect, 17) = ""
Cells(rowSelect, 14) = ""
Cells(rowSelect, 18) = ""

Sheets("Home").Select
Cells(rowSelect, 1) = ""
Cells(rowSelect, 2) = ""
Cells(rowSelect, 3) = ""
Cells(rowSelect, 4) = ""
Cells(rowSelect, 5) = ""
Cells(rowSelect, 6) = ""
Cells(rowSelect, 7) = ""
Cells(rowSelect, 8) = ""
Cells(rowSelect, 9) = ""
Cells(rowSelect, 10) = ""
Cells(rowSelect, 11) = ""
Cells(rowSelect, 12) = ""
Cells(rowSelect, 13) = ""
Cells(rowSelect, 14) = ""
Cells(rowSelect, 15) = ""
Cells(rowSelect, 16) = ""

'Delete whole folder
  
Dim FSO As Object
Dim MyPath As String
Set FSO = CreateObject("scripting.filesystemobject")
MyPath = "C:\Projects\Project 2\" & SAR

If Right(MyPath, 1) = "\" Then
MyPath = Left(MyPath, Len(MyPath) - 1)
End If

If FSO.FolderExists(MyPath) = False Then
MsgBox MyPath & " was deleted"
Exit Sub
End If

FSO.DeleteFolder MyPath

Unload Me

End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Try this

VBA Code:
Private Sub CommandButton1_Click()
  'Update SAR
  If Me.ComboBox1.Value = "" Then
    MsgBox "SAR Can Not be Blank!", vbExclamation, "SAR"
    Exit Sub
  End If
 
  SAR = Me.ComboBox1.Value
  Dim rowSelect As Long
  rowSelect = Me.ComboBox1.ListIndex + 6
 
  Sheets("Sheet1").Select
  Rows(rowSelect).Delete
 
  Sheets("Sheet2").Select
  Rows(rowSelect).Delete
 
  Sheets("Sheet3").Select
  Rows(rowSelect).Delete
    
  Sheets("Home").Select
  Rows(rowSelect).Delete
 
  'Delete whole folder
  Dim FSO As Object
  Dim MyPath As String
  Set FSO = CreateObject("scripting.filesystemobject")
  MyPath = "C:\Projects\Project 2\" & SAR
 
  If Right(MyPath, 1) = "\" Then
    MyPath = Left(MyPath, Len(MyPath) - 1)
  End If
 
  If FSO.FolderExists(MyPath) = False Then
    MsgBox MyPath & " was deleted"
    Exit Sub
  End If
  FSO.DeleteFolder MyPath
  Unload Me
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,596
Messages
6,120,438
Members
448,966
Latest member
DannyC96

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top