If there is unhighlighted data after the highlighted cell in a row then we have to clear all the data from start till highlighted cell and paste the unhighlighted data from start in the row

If there is unhighlighted   data after the highlighted cell in a row then we have to clear all the data from start  till highlighted cell and paste the unhighlighted data from start in the row
and if there is no data after the highlighted cell in a row then simply copy and paste that row don’t do anything with that row
Sample-7.xlsm
Avinash SinghAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You may try something like this...
Sub UnHighlightedData()
Dim lr As Long, lc As Long, i As Long, j As Long, c As Long
lr = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lr
    lc = Cells(i, Columns.Count).End(xlToLeft).Column
    For j = lc To 2 Step -1
        If Cells(i, j).Interior.ColorIndex = xlNone Then
            c = j - 1
        ElseIf Cells(i, j).Interior.ColorIndex <> xlNone Then
            Exit For
        End If
    Next j
    If c <> 0 Then Range(Cells(i, 2), Cells(i, c)).Delete shift:=xlToLeft
    c = 0
Next i
End Sub

Open in new window

In the attached, click the button called "Shift Data" on Sheet1 to run the code.
Sample-7.xlsm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Avinash SinghAuthor Commented:
Thnx again  Subodh Tiwari (Neeraj) Sir for giving ur precious time
u r very supportive sir
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Avinash!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.