Another type of Fill

mole999

Well-known Member
Joined
Oct 23, 2004
Messages
10,524
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
I was provide this blindlingly fast filler (by Fluff)

Code:
Sub Mole999()
    Dim Rng As Range
    
    For Each Rng In Range("Y:Y").SpecialCells(xlBlanks).Areas
        If LCase(Rng.Offset(-1).Resize(1).Value) = "on" Then Rng.Value = "ON"
    Next Rng
End Sub

I now have a stock control sheet that like a pivot only provides the first instance of a label until the type changes and needs to adapt what is done

So the area to check is down column B, I've processed the sheet to put the first label at B1 "LabelA", the next label LabelB appears at B198 so need to fill between B1 to B197, then do for the next label.

I get the last row value from C which currently 3754

would
If LCase(Rng.Offset(-1).Resize(1).Value) = "labelA" Then Rng.Value = "LabelA"
If LCase(Rng.Offset(-1).Resize(1).Value) = "labelB" Then Rng.Value = "LabelB"

be efficient (subject to no new labels added)? I think I can kludge it but that's not ideal, any tweaks?
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
If 'LabelX' is literal then perhaps something like
VBA Code:
If Left(LCase(Rng.Offset(-1).Resize(1).Value), 5)= "label" Then Rng.Value = "Label" & UCase(Mid(Rng.Offset(-1).Resize(1).Value, 6, 1)
If you need to list different 'labels' then select case would probably be more efficient than a long list of If's.
 
Upvote 0
If 'LabelX' is literal then perhaps something like
VBA Code:
If Left(LCase(Rng.Offset(-1).Resize(1).Value), 5)= "label" Then Rng.Value = "Label" & UCase(Mid(Rng.Offset(-1).Resize(1).Value, 6, 1)
If you need to list different 'labels' then select case would probably be more efficient than a long list of If's.
Thanks Jason, I soldiered on with what I had and just created the static ones at the moment, the Label is not literal it could be anything, and fell into the trap my references weren't lower case, not expecting them to change too often, just wondered if it could be more human proof
 
Upvote 0
How about if you use the theory of

VBA Code:
UCase(Left(x, 1)) & LCase(Mid(x, 2, Len(x) - 2)) & UCase(Right(x, 1))

Where x refers to the cell with the original label?
 
Upvote 0
for the ones I had it was quicker to put in as all lower case, I can see how that could work being tweaked :D
 
Upvote 0

Forum statistics

Threads
1,215,869
Messages
6,127,421
Members
449,382
Latest member
DonnaRisso

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