Test for value

tourless

Board Regular
Joined
Feb 8, 2007
Messages
144
Office Version
  1. 365
Platform
  1. Windows
Hi Folks.

I have copied values in cells M21:R21, but sometimes they might be blank. I need to test for a value and if one is present, place this formula in the cell directly below it.

"=(ROUND(R[-1]C,2),"

I'm not sure how to write the code to accomplish this. but here's what I'm working with... you can see the mess I'm making and I bet this can also be done without the selects.

VBA Code:
For Each cell In Range("M21:R21")
    If cell <> "" Then
    Range("M22").FormulaR1C1 = "=(ROUND(R[-1]C,2),"
    Else
    
    Range("M22").FormulaR1C1 = "=IFERROR(ROUND(R[-1]C,2),"",=(ROUND(R[-1]C,2)"
    Range("M22").Copy
    Range("N22:R22").Paste
    Application.CutCopyMode = False
    Range("M22:R22").Select
    Selection.Style = "Percent"
    Selection.Copy
    Range("B21").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Perhaps:
VBA Code:
Sub tourless()
Range("M22:R22").FormulaR1C1 = "=ROUND(R[-1]C,2)"
Range("B21").Resize(1, 6).Value = Range("M22:R22").Value
Range("B21").Resize(1, 6).Replace 0, "", xlWhole
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,376
Members
449,080
Latest member
Armadillos

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