Colour a Chosen Row

charllie

Well-known Member
Joined
Apr 6, 2005
Messages
986
Hi Folks,

I have a code linked to menu in my menu bar that allows me to highlight a row in a worksheet and then click this menu/button and it copies the choosen row and pastes it to another worksheet.

Does anyone know a code that i could add to my present that when the information is copied it will colour the selected row yellow.

I have looked at a few posts on MrExcel but cant seem to adapt any to work for me.

Thanks
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
charlie,

Post your code mate, then we can see what we're working with.

But something along these lines should do what you need, as long as the entire row is still selected...

Selection.Interior.ColorIndex = 6

Bob
 
Upvote 0
Hi Bob,

Thanks for your reply.

Heres my code:
Code:
Dim bSelected() As Boolean, iPtr As Integer, lCur As Long, lRow As Long
    Dim R As Range
    Dim vFrCols As Variant, vData() As Variant
    Dim wsTo As Worksheet

    If ActiveSheet.Name <> "Schedule 2" Then
        MsgBox "Currently Active Sheet Is Not Warehouse Schedule"
        Sheets("Schedule 2").Select
        Exit Sub
    End If

    Set wsTo = Sheets("Priority List")
    ReDim bSelected(0 To 0)
    
    For Each R In Selection
        lCur = R.Row
        If UBound(bSelected) < lCur Then ReDim Preserve bSelected(0 To lCur)
        bSelected(lCur) = True
    Next R
    
    vFrCols = Split(expression:="A,F,B,J,I", delimiter:=",")
    ReDim vData(1 To UBound(vFrCols) + 1)
    lRow = 4 'This tells it where to place the information copied starting at row 5
    For lCur = 2 To UBound(bSelected)
        If bSelected(lCur) = True Then
            lRow = lRow + 1
            'wsTo.Rows("5:5").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromRightOrBelow
            For iPtr = 0 To UBound(vFrCols)
                vData(iPtr + 1) = Cells(lCur, vFrCols(iPtr)).Value
            Next iPtr
            wsTo.Range("B" & lRow, Cells(lRow, UBound(vData)).Address).Value = vData
        End If
    Next lCur

I am not quite sure where to place yours. Can you point the obvious out to me please :oops:

Thanks
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,565
Members
449,038
Latest member
Guest1337

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