Work with part of selection VBA

shippey121

Well-known Member
Joined
Mar 21, 2006
Messages
1,003
hi all

started a new role and using excel more and more, no expert in VBA a novice at best but trying to learn. currently stuck on a way to accomplish this so thought id ask.

i want to select and area and format only part of the selection. the code below will format the entire selection, if i selected say A1 to F10 and wanted to colour only the 5th column of the selection, so in this case, E1:E10 green,

Code:
 With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
    End With

i tried this but it still format the entire selection
Code:
With Selection.Cells(, 5)
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
    End With
End With

doing this
Code:
 With Selection.Cells(, 5).Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
    End With

formats the 5th column but only on the first row

any help would be appreciated
 
Last edited:

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
i could do, but the code isnt just to format the area, i already have code that sets the selection as the print area, fits to one page, then exports as PDF and attaches the PDF to an email. i just then type any info i want in the email and press send.

what happens is sometimes i forget which ive emailed and have to look through my sent items to check

certain rows are shaded already so i cant colour the entire selection, im just trying to automate it further

thanks
 
Upvote 0
Try this:

Code:
With Selection.Columns(5).Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
    End With
 
Upvote 0
so close.

worked fine.

changed it to
Code:
With Selection.Columns(5)
        .Value = Now()
    End With
so it puts time i emailed data

thanks
 
Upvote 0
Glad I was able to help you. Come back here to Mr. Excel next time you need additional assistance.
so close.

worked fine.

changed it to
Code:
With Selection.Columns(5)
        .Value = Now()
    End With
so it puts time i emailed data

thanks
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

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