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
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

fairwinds

MrExcel MVP
Joined
May 15, 2003
Messages
8,638
Hi,

Maybe:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range(ActiveCell, ActiveCell.Offset(0, 1)).Interior.ColorIndex = 3
ActiveCell.Offset(0, 2) = ActiveCell.Offset(0, 1)
End Sub
 
Upvote 0

SIXTH SENSE

Well-known Member
Joined
Oct 29, 2003
Messages
1,883
Hi!
Unfortunately there is no onclick event in xcel.
but you can use the slection change event instead.but i suggest the double click event to do this!

try this one.
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Target.Interior.ColorIndex = 3
    Target.Offset(0, 1).Interior.ColorIndex = 3
    Target.Offset(0, 2).Value = Target.Offset(0, 1).Value
    Cancel = True
End Sub
 
Upvote 0

staticbob

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

But how do I undo that ? I only want this to show when the cell is active.

Cheers
 
Upvote 0

SIXTH SENSE

Well-known Member
Joined
Oct 29, 2003
Messages
1,883
ok!
try this

<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">If</SPAN> LastCell.Target <> "" <SPAN style="color:#00007F">Then</SPAN>
        Range(LastCell.Target).Interior.ColorIndex = LastCell.ColorIndex
        Range(LastCell.Target).Offset(0, 1).Interior.ColorIndex = LastCell.ColorIndex
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
    LastCell.Target = Target.Address
    LastCell.ColorIndex = Target.Interior.ColorIndex
    Target.Interior.ColorIndex = 3
    Target.Offset(0, 1).Interior.ColorIndex = 3
    Target.Offset(0, 2).Value = Target.Offset(0, 1).Value
    Cancel = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

Then paste this in standard module


<font face=Courier New><SPAN style="color:#00007F">Type</SPAN> CellX
    Target <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
    ColorIndex <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Type</SPAN>
</FONT>
 
Upvote 0

staticbob

Well-known Member
Joined
Oct 7, 2003
Messages
1,079
Thanks SS, that works in practice, but now I need to get it into my file.

The main problem being that I have different sections to apply this to. See below. If I double click on a cell in section 1.1, column B, I want to copy the options from Col C to that sections score.

I have 25 sections ! Do I need to write all this into an IF statement ? If active cell is this, then write to this etc ?

cheers
Bob
Master Op Ass Feb 04.xls
ABCD
13OptionsScore
141.0PROCUREMENT
151.1TenderType10
16BillofQuantities20
17CostPlus20
18TermMaintenance15
19Design&Build15
20BillofQuantswithCDP10
21Spec&Drawings10
22ManagementFee10
23Bespokecontract/GMP5
24Design&BuildNovated5
251.2ProcurementRoute15
260ther?
272stage20
28Partnered20
29Negotiated(tenderlist1of1)30
30Competitive15
31PPP15
32PFI15
331.3CommercialScope6
34Markedsubjectively;between0and100-10
35{anyscoreover5mustsetoutbasisforscore}
Opportunity
 
Upvote 0

staticbob

Well-known Member
Joined
Oct 7, 2003
Messages
1,079
Yes, unfortunately. Each is merged and applies to the section. The entry in column D would equate to whichever cell had been double-clicked.

I can redesign if this would be better ?

Bob
 
Upvote 0

SIXTH SENSE

Well-known Member
Joined
Oct 29, 2003
Messages
1,883
ok!
here I am again!

<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">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>
    <SPAN style="color:#00007F">If</SPAN> LastCell.Target <> "" <SPAN style="color:#00007F">Then</SPAN>
        Range(LastCell.Target).Interior.ColorIndex = LastCell.ColorIndex
        Range(LastCell.Target).Offset(0, 1).Interior.ColorIndex = LastCell.ColorIndex
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
    LastCell.Target = Target.Address
    LastCell.ColorIndex = Target.Interior.ColorIndex
    Target.Interior.ColorIndex = 3
    Target.Offset(0, 1).Interior.ColorIndex = 3
    
    <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
        <SPAN style="color:#00007F">Else</SPAN>
            MA.Cells(1, 1).Value = Target.Offset(0, 1).Value
        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>

    Cancel = <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,187,175
Messages
5,962,044
Members
438,578
Latest member
MrJimC

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
Top