IF Cell is BLANK Copy & Paste Value From Another Cell With a MACRO

Buns1976

Board Regular
Joined
Feb 11, 2019
Messages
194
Office Version
  1. 365
Platform
  1. Windows
Good Morning Folks,
In my worksheet(SHIFT) I have a range of cells(A4-A35) that are imported. Occasionally there are cells that are BLANK. I need to run a formula in a macro that tests A4-A35 for BLANKS. Example if A4 were BLANK, It copies N4 and paste special, value in A4 and so forth to A35.

Any help would be appreciated.

Thanks,
B
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
This macro with loop could be a simple solution as long as the blank cells in column A are 'really' empty. Imported cells may contain non visible characters if massively imported.
VBA Code:
Option Explicit
Sub CopyOnBlanks()
    Dim x      As Long
    For x = 4 To 35
        With Sheets("SHIFT")
            If .Cells(x, "A") = "" Then .Cells(x, "A") = .Cells(x, "N").Value
        End With
    Next x
End Sub
 
Upvote 0
Solution
This macro with loop could be a simple solution as long as the blank cells in column A are 'really' empty. Imported cells may contain non visible characters if massively imported.
VBA Code:
Option Explicit
Sub CopyOnBlanks()
    Dim x      As Long
    For x = 4 To 35
        With Sheets("SHIFT")
            If .Cells(x, "A") = "" Then .Cells(x, "A") = .Cells(x, "N").Value
        End With
    Next x
End Sub
That works well! Thank you!! I wonder if we could add this to the macro after the copy and paste? In column H4-H35 I have this formula =MID(A4,10,3). If cell A4 is blank and the macro does the copy & paste then change the formula in H4 to =MID(A4,10,3)+1 and so forth to H35?
 
Upvote 0
Do you mean like this ?
VBA Code:
Option Explicit
Sub CopyOnBlanks()
    Dim x      As Long
    For x = 4 To 35
        With Sheets("SHIFT")
            If .Cells(x, "A") = "" Then
                .Cells(x, "A") = .Cells(x, "N").Value
                .Cells(x, "H").FormulaR1C1 = "=MID(RC[-7],10,3)+1"
            End If
        End With
    Next x
End Sub
 
Upvote 0
Do you mean like this ?
VBA Code:
Option Explicit
Sub CopyOnBlanks()
    Dim x      As Long
    For x = 4 To 35
        With Sheets("SHIFT")
            If .Cells(x, "A") = "" Then
                .Cells(x, "A") = .Cells(x, "N").Value
                .Cells(x, "H").FormulaR1C1 = "=MID(RC[-7],10,3)+1"
            End If
        End With
    Next x
End Sub
Perfect!! Thank you so much!!
 
Upvote 0
Thanks for the positive feedback(y), glad having been of some help.

Ps. sure you got the solution mark on the right post ?
 
Upvote 0
Thanks for the positive feedback(y), glad having been of some help.

Ps. sure you got the solution mark on the right post ?
I Jumped the gun! The formula in the macro (.Cells(x, "H").FormulaR1C1 = "=MID(RC[-7],10,3)+1") needs be the + the value in J4-J35 instead of "+1". Is that doable?
 
Upvote 0
I Jumped the gun! The formula in the macro (.Cells(x, "H").FormulaR1C1 = "=MID(RC[-7],10,3)+1") needs be the + the value in J4-J35 instead of "+1". Is that doable?
Disregard for now. I believe I got it! Thanks again!
 
Upvote 0

Forum statistics

Threads
1,215,231
Messages
6,123,756
Members
449,120
Latest member
Aa2

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