Format active cell

staticbob

Well-known Member
Joined
Oct 7, 2003
Messages
1,079
Hi,

How would I format the active cell when it is selected, and the one to its right the same. Then copy the data in the 2nd cell to another.

eg, click on cell A1, both A1 AND A2 are highlighted red, AND the value in A2 is copied to A3

Cheers !
Bob
 
Insert this in the standard module of that workbook


Code:
Type CellX
    Target As String
    ColorIndex As Integer
End Type
 
Upvote 0

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
OK, another problem, and I dont think this will be so easy !

I need to retain the formatting for each section. So as my original example posted, shaded in yellow. I can only have one row higlighted in each section !

Like I said, I've got 30 odd sections, all of different size !

Any ideas ?
 
Upvote 0
What format?
The code doesnt delete any conditional formating.
It change the background while you want it. now if you want to change the highlighted one, the formating of the previous is restored.
Each time you doble click one row in B, the color in there is saved and regain when other cells are double click.
 
Upvote 0
Sorry, let me try to explain clearer . . .

The code works fine, but I need to do this for each secton. I need to have a formatted selection in each of the sectons.

In section 1.1, I want to be able to double click to select a score, only highlighting one row.
When I move onto section 1.2, I want to retain the format of the cells clicked in the latest row of section 1.1

Is this any clearer ?

Bob
Master Op Ass Feb 04.xls
ABCD
151.1TenderType20
16BillofQuantities20
17CostPlus20
18TermMaintenance15
19Design&Build15
20BillofQuantswithCDP10
21Spec&Drawings10
22ManagementFee10
23Bespokecontract/GMP5
24Design&BuildNovated5
251.2ProcurementRoute30
260ther?
272stage20
28Partnered20
29Negotiated(tenderlist1of1)30
30Competitive15
31PPP15
32PFI15
Opportunity
 
Upvote 0
These are the boundries on each of the first 6 sections . . .

B16 - B24
B26 - B32
B41 - B47
B51 - B59
B71 - B76
B79 - B87

Thanks !!! I need to retain a selection (red format) in each one of these sections !
 
Upvote 0
Yes. That would work the same. I was just highlighting the cells that I would use your double-click code on.

Thanks alot.
 
Upvote 0
Hi bob!

You right. Its realy tough!
see if this is what you wanted. and try the code below.
coloring.xls
ABCD
1OptionsScore
2PROCUREMENT
31.1Tender??Type20
4Bill?of?Quantities20
5Cost?Plus20
6Term?Maintenance15
7Design?&?Build15
8Bill?of?Quants?with?CDP10
9Spec?&?Drawings10
10Management?Fee10
11Bespoke?contract?/?GMP5
12Design?&?Build?Novated5
131.2Procurement?Route20
140ther?
152?stage?20
16Partnered20
17Negotiated?(tender?list?1?of?1)30
18Competitive15
19PPP15
20PFI15
211.3Commercial?Scope0-10
22Marked?subjectively;?between?0?and?100-10
23{any?score?over?5?must?set?out?basis?for?score}
Sheet1


The code!<font face=Courier New><SPAN style="color:#00007F">Private</SPAN><SPAN style="color:#00007F">Sub</SPAN> Worksheet_BeforeDoubleClick(<SPAN style="color:#00007F">ByVal</SPAN> Target<SPAN style="color:#00007F">As</SPAN> Range, Cancel<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Boolean</SPAN>)
    <SPAN style="color:#00007F">Static</SPAN> LastCell<SPAN style="color:#00007F">As</SPAN> CellX
    <SPAN style="color:#00007F">Static</SPAN> Grpcell()<SPAN style="color:#00007F">As</SPAN> CellX
    <SPAN style="color:#00007F">Static</SPAN> Initx<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Boolean</SPAN>
    <SPAN style="color:#00007F">Set</SPAN> isect = Application.Intersect(Target, Range("b:B"))
    <SPAN style="color:#00007F">If</SPAN> isect<SPAN style="color:#00007F">Is</SPAN><SPAN style="color:#00007F">Nothing</SPAN><SPAN style="color:#00007F">Then</SPAN><SPAN style="color:#00007F">Exit</SPAN><SPAN style="color:#00007F">Sub</SPAN>
Redimx:
    <SPAN style="color:#00007F">If</SPAN><SPAN style="color:#00007F">Not</SPAN> Initx<SPAN style="color:#00007F">Then</SPAN>
        <SPAN style="color:#00007F">ReDim</SPAN><SPAN style="color:#00007F">Preserve</SPAN> Grpcell(Application.WorksheetFunction.CountA(Range("a:A")) - 1)<SPAN style="color:#00007F">As</SPAN> CellX
        k = 2<SPAN style="color:#007F00">'blank cel in A before the first entry in A</SPAN>
        <SPAN style="color:#00007F">For</SPAN> I =<SPAN style="color:#00007F">LBound</SPAN>(Grpcell)<SPAN style="color:#00007F">To</SPAN><SPAN style="color:#00007F">UBound</SPAN>(Grpcell) - 1
            <SPAN style="color:#00007F">While</SPAN> Range("A" & k).Value = ""
                k = k + 1
            <SPAN style="color:#00007F">Wend</SPAN>
                st = k
                k = k + 1
            <SPAN style="color:#00007F">While</SPAN> Range("A" & k).Value = ""
                k = k + 1
            <SPAN style="color:#00007F">Wend</SPAN>
                k = k - 1
                en = k
            <SPAN style="color:#00007F">Set</SPAN> Grpcell(I).Rng = Range("b" & st & ":b" & en)
        <SPAN style="color:#00007F">Next</SPAN> I
        <SPAN style="color:#00007F">Set</SPAN> Grpcell(I).Rng = Range("b" & k + 1 & ":b" & Range("b65536").End(xlUp).Row)
        Initx =<SPAN style="color:#00007F">True</SPAN>
    <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN>
    <SPAN style="color:#00007F">If</SPAN> (Initx) And ((Application.WorksheetFunction.CountA(Range("a:A")) - 1)<><SPAN style="color:#00007F">UBound</SPAN>(Grpcell))<SPAN style="color:#00007F">Then</SPAN>
        Initx =<SPAN style="color:#00007F">False</SPAN>
        <SPAN style="color:#00007F">ReDim</SPAN> Grpcell(0)<SPAN style="color:#00007F">As</SPAN> CellX
        <SPAN style="color:#00007F">GoTo</SPAN> Redimx
    <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN>
    <SPAN style="color:#00007F">For</SPAN> I =<SPAN style="color:#00007F">LBound</SPAN>(Grpcell)<SPAN style="color:#00007F">To</SPAN><SPAN style="color:#00007F">UBound</SPAN>(Grpcell)
    <SPAN style="color:#00007F">Set</SPAN> isect = Application.Intersect(Grpcell(I).Rng, Target)
    <SPAN style="color:#00007F">If</SPAN><SPAN style="color:#00007F">Not</SPAN> isect<SPAN style="color:#00007F">Is</SPAN><SPAN style="color:#00007F">Nothing</SPAN><SPAN style="color:#00007F">Then</SPAN>
        <SPAN style="color:#00007F">If</SPAN> Grpcell(I).Target<SPAN style="color:#00007F">Is</SPAN><SPAN style="color:#00007F">Nothing</SPAN><SPAN style="color:#00007F">Then</SPAN>
            <SPAN style="color:#00007F">Set</SPAN> Grpcell(I).Target = Target
            Grpcell(I).ColorIndex = Target.Interior.ColorIndex
            Target.Offset(0, 0).Interior.ColorIndex = 3
            Target.Offset(0, 1).Interior.ColorIndex = 3
            <SPAN style="color:#00007F">Exit</SPAN><SPAN style="color:#00007F">For</SPAN>
        <SPAN style="color:#00007F">Else</SPAN>
            Range(Grpcell(I).Target.Address).Interior.ColorIndex = Grpcell(I).ColorIndex
            Range(Grpcell(I).Target.Address).Offset(0, 1).Interior.ColorIndex = Grpcell(I).ColorIndex
            <SPAN style="color:#00007F">Set</SPAN> Grpcell(I).Target = Target
            Grpcell(I).ColorIndex = Target.Interior.ColorIndex
            Target.Offset(0, 0).Interior.ColorIndex = 3
            Target.Offset(0, 1).Interior.ColorIndex = 3
            <SPAN style="color:#00007F">Exit</SPAN><SPAN style="color:#00007F">For</SPAN>
        <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN>
    <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN><SPAN style="color:#00007F">Next</SPAN> I
    <SPAN style="color:#00007F">Set</SPAN> MA = Target.Offset(0, 2).MergeArea
        
        <SPAN style="color:#00007F">If</SPAN> MA.Address = Target.Offset(0, 2).Address<SPAN style="color:#00007F">Then</SPAN>
            Target.Offset(0, 2).Value = Target.Offset(0, 1).Value
            MsgBox ""
        <SPAN style="color:#00007F">Else</SPAN>
            <SPAN style="color:#00007F">If</SPAN> MA.Cells(1, 1).Value<> Target.Offset(0, 1).Value<SPAN style="color:#00007F">Then</SPAN>
                MA.Cells(1, 1).Value = Target.Offset(0, 1).Value
            <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN>
        <SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">If</SPAN>
    Cancel =<SPAN style="color:#00007F">True</SPAN>
    Application.ScreenUpdating =<SPAN style="color:#00007F">True</SPAN><SPAN style="color:#00007F">End</SPAN><SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0

Forum statistics

Threads
1,215,028
Messages
6,122,753
Members
449,094
Latest member
dsharae57

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