Simple Fix - Populate cell with value from specific worksheet

albytross

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

I have this code which almost does exactly what I need it to.
Instead of populating cells with the word Test, how could i make it populate cells with the exact value on worksheet ABC, cell A2?

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

    Set ws = ThisWorkbook.Sheets("XYZ")

    With ws
        lRow = .Range("C" & .Rows.Count).End(xlUp).Row

        .Range("B2:B" & lRow).Formula = "=If(C2<>"""",""Test"","""")"
        .Range("B2:B" & lRow).Value = .Range("B2:B" & lRow).Value
    End With
End Sub
 

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.
as simple as an equals sign

""=ABC!A2""
VBA Code:
Sub Sample()
    Dim ws As Worksheet
    Dim lRow As Long

    Set ws = ThisWorkbook.Sheets("XYZ")

    With ws
        lRow = .Range("C" & .Rows.Count).End(xlUp).Row

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

Forum statistics

Threads
1,214,919
Messages
6,122,259
Members
449,075
Latest member
staticfluids

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