Populate a cell when another cell is not blank

detriez

Board Regular
Joined
Sep 13, 2011
Messages
193
Office Version
  1. 365
Platform
  1. Windows
I am trying to get this to populate all cells in BJ (not the header cell BJ1) with "USD" when Cells in column B are not blank

This is throwing a Run-time error 424: Object Required error on "If Range....)
VBA Code:
    Dim LastRow As Long
    Dim i As Long
    LastRow = Range("B" & Rows.Count).End(xlUp).Row
    For i = 2 To LastRow
        If Range("B" & i) Is Not Null Then
            Range("BJ" & i).Value = "USD"
        End If
    Next i
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try
VBA Code:
If Range("B" & i)<>"" Then
 
Upvote 0
Solution
Another option without the loop
VBA Code:
Sub detriez()
   With Range("B2", Range("B" & Rows.Count).End(xlUp))
      .Offset(, 60).Value = Evaluate(Replace("if(" & .Address & "<>"""",""USD"",if(@="""","""",@))", "@", .Offset(, 60).Address))
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,547
Messages
6,125,461
Members
449,228
Latest member
moaz_cma

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