Shift up values to fill in blank cells

bujubenji

New Member
Joined
Feb 26, 2023
Messages
13
Office Version
  1. 365
Platform
  1. Windows
Evening all,

I wonder if you can provide some advice. I have a sheet in place which records when goods are sent with the click of a button "btnR44"
This will copy cells across to another range. Please see code here for clarity :

"Sub btnR44_click()

With ActiveSheet

Range("B44:E44").Copy
Range("B44:E44").Interior.Color = RGB(136, 212, 138)
.Range("H" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues

Application.CutCopyMode = False

.Shapes("btnR44").Visible = False
.Shapes("R44clk").Visible = True

Application.Speech.Speak "sent to Q.A. ", speakasync:=True

End With
End Sub"

I am attempting to code the removal of info that was sent over in the event of human error or similar. i.e. B44:E44 holds info on a particular good, I click a button on row 44 which copies the info over to H44:K44 and so on down to row 58.

If for example, someone mistakenly pressed that button, I want a secondary click to remove the data from H44:K44 and shift any subsequent data up to fill in the blank row.


Sub btnR44_unclick()

With ActiveSheet

.Shapes("btnR44").Visible = True
.Shapes("R44clk").Visible = False
Range("B44:E44").Interior.Color = xlNone

Dim rng As Range
Set rng = Range("h44:K58").Find(what:=Range("B44:E44").Value, LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlNext, MatchCase:=False)
rng.ClearContents
rng.Offset(0, 1).ClearContents
rng.Offset(0, 2).ClearContents
rng.Offset(0, 3).ClearContents

'here I want to make it so that the blank row which is now present, will be filled by the subsequent row of data.
'or in other words, I want to shift up all values to fill in any blank row in the range H44:K58
'I found the below on another forum, but it results in a Run-time error '1004' Application-defined or object-defined error'


With Range("H44:K58")
For i = .Rows.Count To 1 Step -1
If IsEmpty(.Cells(i, 1)) Then .Rows(i).Clear Shift:=xlUp 'This snippet is highlighted on debug

Next
End With
End With
End Sub

Any help would be fantastic!

Thanks.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
...
If for example, someone mistakenly pressed that button, I want a secondary click to remove the data from H44:K44 and shift any subsequent data up to fill in the blank row.
...
How about:
VBA Code:
    Range("H44:K44").Delete
 
Upvote 0
Solution:

Dim rng As Range
Set rng = Range("H44:K58").Find(what:=Range("B44:E44").Value, LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlNext, MatchCase:=False)
rng.ClearContents
rng.Offset(0, 1).ClearContents
rng.Offset(0, 2).ClearContents
rng.Offset(0, 3).ClearContents
Range("H44:K58").SpecialCells(xlCellTypeBlanks).Delete Shift:=xlShiftUp
 
Upvote 0
Solution

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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