VBA to copy selected cell value to next empty cell in a range

MeaclH

Board Regular
Joined
Apr 2, 2014
Messages
77
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi there,

I have a VBA that works perfectly fine for its current use, however I need it to be more specific about where it pastes the data.
I really need a code that takes the value in a selected cell, copies it to the next empty cell in the column between rows 4-8, adds cell colour fill formatting to new cell and then applies strikethrough formatting to the original selected cell.

For example
H18 is selected cell.
Value copied to next empty cell in range H4:8
Formatting for new cell fill colour #FF7C80
Strikethrough applied to value in H18

Thanks heaps for any help you may have.

Hayden
 
Last edited:

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
@MeaclH I'm assuming you want similar for more columns than just H ?

Maybe try like below.

VBA Code:
Sub Copyandstrike()
Dim r As Integer, c As Integer

If Selection.Cells.Count > 1 Then Exit Sub

c = Selection.Column '????*No check on validity of columnn!'

For r = 4 To 8
    If Cells(r, c) = vbNullString Then
        Cells(r, c).Value = Selection.Value
        Cells(r, c).Interior.Color = RGB(100, 49, 50) 'Edit RGB values if necessary
        Selection.Font.Strikethrough = True
        r = 0
        Exit For
     End If
Next

If Not r = 0 Then MsgBox "There are no blanks left!"

End Sub
HTH
 
Upvote 0
Solution
Tony you're the man! Thanks mate.
@MeaclH I'm assuming you want similar for more columns than just H ?

Maybe try like below.

VBA Code:
Sub Copyandstrike()
Dim r As Integer, c As Integer

If Selection.Cells.Count > 1 Then Exit Sub

c = Selection.Column '????*No check on validity of columnn!'

For r = 4 To 8
    If Cells(r, c) = vbNullString Then
        Cells(r, c).Value = Selection.Value
        Cells(r, c).Interior.Color = RGB(100, 49, 50) 'Edit RGB values if necessary
        Selection.Font.Strikethrough = True
        r = 0
        Exit For
     End If
Next

If Not r = 0 Then MsgBox "There are no blanks left!"

End Sub
HTH
Tony you're the man! Thanks mate
 
Upvote 0

Forum statistics

Threads
1,223,837
Messages
6,174,927
Members
452,593
Latest member
Jason5710

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