Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 397
Default If active cell value is 1, run this macro

Hi There,

Situation - if you select the active cell then click a box, a macro runs
based on the colour in your active cell.
I would like to modify the VBA slightly (see below) to say if the value
of the active cell is 1, then run macro 1x (call "1X"), if cell value is
2, then call Macro 2x, etc.
This is what my existing Macro looks like:

Public Sub Colour_views()

Call unhide_cols

Dim objWS As Excel.Worksheet
Dim objCell As Excel.Range, objR As Excel.Range
Dim i As Byte
Dim J As Long

Set objWS = Sheets("Master")
' Don't forget that wherever you're looking at, the selected cell needs
to have a background
' color that matches the various "views" you've built on the master
sheet.

Set objCell = Application.Selection

J = objCell.Interior.ColorIndex

' Hide columns
' If columns A - E are always going to be there, we only need to start
with Column E, which
' is column number 5.
For i = 6 To 168

Set objR = objWS.Cells(2, i) ' We'll always be looking at row 2 -
the column will change
If objR.Interior.ColorIndex < J Then

objWS.Columns(i).Hidden = True

End If

Next

Set objR = Nothing
Set objCell = Nothing
Set objWS = Nothing

Sheets("master").Select
End Sub


Thanks!!!!!!!

D

*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default If active cell value is 1, run this macro

Select Case objCell.Value
Case 1
Call x1
Case 2
Call x2
Case 3
Call x3
End Select

Hints:
1) Subs can't be named "1X", can't have numeric character first. Try "X1"
(or something more descriptive!)
2) Dim i As Long, Byte may work but I why limit yourself? I don't even
bother with Integer anymore (unless required for a Sub or Function arg)
3) Terminology: You don't select the active cell; you select a cell and it
becomes the active cell. :)


"Darin Kramer" wrote:

Hi There,

Situation - if you select the active cell then click a box, a macro runs
based on the colour in your active cell.
I would like to modify the VBA slightly (see below) to say if the value
of the active cell is 1, then run macro 1x (call "1X"), if cell value is
2, then call Macro 2x, etc.
This is what my existing Macro looks like:

Public Sub Colour_views()

Call unhide_cols

Dim objWS As Excel.Worksheet
Dim objCell As Excel.Range, objR As Excel.Range
Dim i As Byte
Dim J As Long

Set objWS = Sheets("Master")
' Don't forget that wherever you're looking at, the selected cell needs
to have a background
' color that matches the various "views" you've built on the master
sheet.

Set objCell = Application.Selection

J = objCell.Interior.ColorIndex

' Hide columns
' If columns A - E are always going to be there, we only need to start
with Column E, which
' is column number 5.
For i = 6 To 168

Set objR = objWS.Cells(2, i) ' We'll always be looking at row 2 -
the column will change
If objR.Interior.ColorIndex < J Then

objWS.Columns(i).Hidden = True

End If

Next

Set objR = Nothing
Set objCell = Nothing
Set objWS = Nothing

Sheets("master").Select
End Sub


Thanks!!!!!!!

D

*** Sent via Developersdex http://www.developersdex.com ***

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro-active cell puiuluipui Excel Discussion (Misc queries) 3 March 14th 10 04:21 PM
Macro to paste in the active cell the contents of a cell from another file?? LarryB Excel Programming 3 June 12th 06 06:37 PM
Macro to set Active Cell Graham Daniels Excel Programming 6 September 11th 04 11:17 PM
Run macro in active cell ku Excel Programming 4 August 6th 04 06:36 PM
Run a macro in the active cell. Jasmine[_2_] Excel Programming 1 January 5th 04 03:47 PM


All times are GMT +1. The time now is 02:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"