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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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,575
Messages
6,125,631
Members
449,241
Latest member
NoniJ

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