First column instance and fill right

silverspr

New Member
Joined
Mar 15, 2011
Messages
2
Hello everyone
I've found lots of vba examples of how to fill down a range of data but nothing to fill right on the first column instance of a value:

I have a range of data C2:H19
Each row has one value which could start anywhere in the row. I need to be able to either select the range or find the first instance of the value in the row and fill to the right with that value to the last column (H) i.e. row C2:H2, first value in this row might be D2, fill right to H2 with the value from D2, next row the value might be in E3, fill right to H3 with the value from E3 and so on.

Any help on this will be muchly appreciated
thanks
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi and welcome.

Code:
Sub Fill_to_Right()

    Dim cell As Range, Found As Range
    
    For Each cell In Range("C2:C19")
        Set Found = cell.Resize(, 6).Find("*", Cells(cell.Row, "H"), , , xlByColumns, xlNext)
        If Not Found Is Nothing Then
            Range(Found, Cells(cell.Row, "H")).Value = Found.Value
        End If
    Next cell
End Sub
 
Upvote 0
Alpha,
this is fabulous, and in so few lines of code. I will have to study this, not the approach I had taken. I was making it much more complex than it needed to be. Thank you so much, you've saved me tons of work, I have a 50 page worksheet to convert using this macro.

not sure how I award you 5 stars...but its certainly worth 5 stars to me!
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,558
Members
452,928
Latest member
101blockchains

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