select active cell code

ryan_law2000

Well-known Member
Joined
Oct 2, 2007
Messages
738
hey everyone,

i have this code
Code:
Private Sub Yellow_Click()
 With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        .TintAndShade = 0
        .PatternTintAndShade = 0
         
    End With
End Sub

Works great other then once the cell/cells are highlighted it does not select a cell. I want it to select the active cell (or bottom cell if a range is selected) after the cell is colored
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
It worked perfect when i used a macro assigned to a button. But i changed it to vba code and now it doesnt work.

I guess a solution could be to have the button run a macro, how would i do that?

Sheet name: Tally
Macro Name: Yellow()
 
Upvote 0
That code should work fine as is, the question is now: how are you kicking off sub "Yellow_Click"?

If you don't tie that code to some event, then it will just sit there and never get run.
 
Upvote 0
sure, so you have something like:

Code:
Private Sub CommandButton1_Click()
    Yellow_Click
End Sub

That should work fine. Unless, you have your button code and your Yellow code in different modules, in which case you should move the Yellow code to the same module (which should be a Sheet), or change your Yellow code from Private to Public.
 
Upvote 0
still not working :(

I have thi in my Module1
Code:
Sub Yellow()
'
' yellow Macro
'

'
    
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
End Sub

and this in sheet1
Code:
Public Sub Yellow_Click()
Yellow_Click
End Sub

all it does is debug and highlight
Yellow_Click under the Public Sub


What am i doing wrong?
 
Upvote 0
Too much yellow stuff,

Should just be:

Code:
Public Sub Yellow_Click()
Yellow
End Sub

because "Yellow" is the name of your sub in the module.
 
Upvote 0
Code:
Public Sub Yellow_Click()
Yellow_Click
End Sub

all it does is debug and highlight
Yellow_Click under the Public Sub

What am i doing wrong?
You have the Yellow_Click event code calling itself. Try changing the Yellow_Click event code to this...
Code:
Public Sub Yellow_Click()
  Yellow
End Sub
where you have it call the Yellow macro instead.
 
Upvote 0
Ok, Calling the macro works good other then its still not selecting the cell after.

I have a picture assigned to the macro and it works perfect, colors the cell then selects it.

When i have this Active X button with code to call the macro "yellow" then it colors the cell but does NOT select any cell.

any solutions?
 
Upvote 0
You haven't written any code to select a cell, so there's no way to expect the macro to select a cell. All your code does is format the current selection. You need to add something like:

Code:
Sub Yellow()
'
' yellow Macro
'
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With

    Selection.Offset(1,0).Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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