All Cell Values in each Area selected to equal first cell Value

Boffa

New Member
Joined
May 8, 2019
Messages
27
Hi Guys,

I'm struggling to code a VBA solution where I have multiple areas selected in one column (each area is split up by a blank row)

What I want to do is for each selected area, all cell values in each Area selected must equal the same cell value as the first cell value of each area

So if the first area selected has four cells in it, then whatever value is in the Second, third, and fourth cell they must be updated to be the same as the cell value in the first cell
The it goes to the next selected area
If the second area selected only has 2 cells selected then the second cell value must equal the first cell value

and so on

if a selected area only consists of one cell in it, then it can just move to the next area

Below is my code so far - which basically just selects all the areas - Any help would be greatly appreciated

Dim lRow As Long
Dim rAreas as Range
Dim c as range

lRow = Cells.Find(What:="*", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row

set rAreas = Sheets(1).range("C2", "C" & lRow).SpecialCells(xlCellTypeConstants, 2)

rAreas.select
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try this:

VBA Code:
Option Explicit

Sub fillAreas()

    Dim lRow As Long
    Dim rAreas As Range
    Dim rng As Range
    Dim c As Range
   
    lRow = Columns("C").Find(What:="*", _
                             LookIn:=xlFormulas, _
                             SearchDirection:=xlPrevious).Row
   
    Set rAreas = Sheets(1).Range("C2", "C" & lRow).SpecialCells(xlCellTypeConstants, xlTextValues)
   
    For Each rng In rAreas.Areas
        If rng.Rows.Count > 1 Then
           rng.Value = rng.Cells(1).Value
        End If
    Next rng

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,432
Messages
6,124,860
Members
449,194
Latest member
HellScout

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