VBA - Enter value if column not blank

albytross

New Member
Joined
Sep 22, 2021
Messages
24
Office Version
  1. 365
Hi,

In sheet XYZ I have values in column B.

I need column A in XYZ to be populated with the value from cell A2 in worksheet "ABC" - but only as far as column B is populated.

Should be easy, maybe so easy nobody has asked before because I can't find a solution online.

Would appreciate some help if anyone has a moment.
 
VBA Code:
Sub XYZ_PopulateFields()
    Dim i As Long, lastr As Long
    'Is activesheet syntax required?
        ActiveSheet.Name = "XYZ"
        lastr = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row
        For i = 2 To lastr
            Range("A" & i) = Evaluate("=IF(B" & i & "<>"""",ABC!A" & i & ","""")")
    Next i
End Sub
This macro will be triggered from a different sheet, so is activesheet syntax required?

The macro showed no interaction with the cells on sheet XYZ.
Also the only entered value on sheet XYZ should come from cell ABC!A2, to populate column A.

Thanks for your help James
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi James,

Solutions:

VBA Code:
Sub XYZ_PopulateFields()
    Dim ws As Worksheet
    Dim lRow As Long

    Set ws = ThisWorkbook.Sheets("XYZ")
    'Column A Project
    With ws
        lRow = .Range("B" & .Rows.Count).End(xlUp).Row

        .Range("A2:A" & lRow).Formula = "=If(B2<>"""",""=ABC!A2"","""")"
        .Range("A2:A" & lRow).Value = .Range("A2:A" & lRow).Value
    End With
 
Upvote 0

Forum statistics

Threads
1,215,475
Messages
6,125,028
Members
449,205
Latest member
Eggy66

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