with Worksheets isn't working correctly

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
721
Office Version
  1. 2016
Platform
  1. Windows
I don't understand why this isn't pasting the value of C4 into C5:C1000. When I run it in any sheet (not Employees) it works except for the pasting. It will paste the range on whatever sheet I'm on, not "Employees", unless of course I'm on the sheet "Employees".

VBA Code:
            With Sheets("Employees").Range("C4")
            .Formula = "=LEFT(B4,2)"
            .Formula = .Value
            .Copy Range("C5:C1000")
            End With

I also tried
VBA Code:
            .Range("C4").Copy Range("C5:C1000")
VBA Code:
            .Range("C4") = Range("C5:C1000")
VBA Code:
            .Range("C4").Value = Range("C5:C1000").Value

On a side note, I'd like this to run only if C4 is empty/blank.

VBA Code:
If Sheets("Employees").Range("C4")="" Then
            With Sheets("Employees").Range("C4")
            .Formula = "=LEFT(B4,2)"
            .Formula = .Value
            .Copy Range("C5:C1000")
            End With
End If

Thank you
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
You forgot the dot in front of the target range:

Code:
.Copy .Range("C5:C1000")
 
Upvote 0
You forgot the dot in front of the target range:

Code:
.Copy .Range("C5:C1000")
Thanks, but even with the change it isn't copying C4 and pasting into C5:C1000
VBA Code:
            With Sheets("Employees").Range("C4")
            .Formula = "=LEFT(B4,2)"
            .Formula = .Value
            .Copy .Range("C5:C1000")
            End With
 
Upvote 0
I had to add the Sheets("Employees") again, seems strange to me. But what do I know
VBA Code:
If Sheets("Employees").Range("C4") = "" Then
            With Sheets("Employees").Range("C4")
            .Formula = "=LEFT(B4,2)"
            .Formula = .Value
            .Copy Sheets("Employees").Range("C5:C1000")
            End With
End If
 
Upvote 0
Sorry - I overlooked your with block holding a cell reference, so it would be:

Code:
.copy .worksheet.Range("C5:C1000")
 
Upvote 0
Solution

Forum statistics

Threads
1,214,654
Messages
6,120,758
Members
448,991
Latest member
Hanakoro

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