Make all the cells in a selction equal the value of the first cell in the selection

NewOrderFac33

Well-known Member
Joined
Sep 26, 2011
Messages
1,275
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Good afternoon,

Quick query for a rush job - I need to write a procedure which, when I select a range of cells, and then run the procedure, all the cells' values will equal the value in the first cell. I did this:

Code:
Sub PopulateAll()
   Dim SelectedCell(1 To 100) As Variant
   For Each SelectedCell In Selection
       SelectedCell.Value = SelectedCell(1).Value 
   Next
End Sub

but Excel reports that "For Each contol variable mus be variant or object"Where am I going wrong, & thanks in advance!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Try

Code:
Sub PopulateAll()
Selection.Value = Selection(1).Value
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,535
Messages
6,055,964
Members
444,839
Latest member
laurajames

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