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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,223,948
Messages
6,175,573
Members
452,652
Latest member
eduedu

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