Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 76
Default Using Case and referencing a cell instead of a value

I'm trying to change the background color of a cell based on a value,
however instead of using the syntax below can you refer to a cell with
a value instead of hardcoding the value in the macro? If you can,
then what is the syntax? thank you in advance

Select Case Range("A1").Value
Case 100
Range("B1").Value = 50
Case 150
Range("B1").Value = 40
Case 200
Range("B1").Value = 30
Case 350
Range("B1").Value = 20
Case 400
Range("B1").Value = 10
Case Else
Range("B1").Value = 0
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 367
Default Using Case and referencing a cell instead of a value

I am not quite sure if that is what you mean:

dim cellrow as long
dim cellcolumn as integer

cellrow = 2
cellcolumn = 2

Select Case Range("A1").Value
Case 100
Cells(cellrow, cellcolumn).Value = 50
Case 150
Cells(cellrow, cellcolumn).Value = 40
Case 200
Cells(cellrow, cellcolumn).Value = 30
Case 350
Cells(cellrow, cellcolumn).Value = 20
Case 400
Cells(cellrow, cellcolumn).Value = 10
Case Else
Cells(cellrow, cellcolumn).Value = 0
end select

you can input data to cellrow and cellcolumn however you want.
if you want to work with letters in cellcolumn do that:

dim cellrow as long
dim cellcolumn as string

cellcolumn = "B"
cellrow = 2

range(cellcolumn & cellrow).value = "bla"


hth

Carlo

On Jan 17, 6:56*am, S Himmelrich wrote:
I'm trying to change the background color of a cell based on a value,
however instead of using the syntax below can you refer to a cell with
a value instead of hardcoding the value in the macro? *If you can,
then what is the syntax? *thank you in advance

* * Select Case Range("A1").Value
* * * * * Case 100
* * * * * * * Range("B1").Value = 50
* * * * * Case 150
* * * * * * * Range("B1").Value = 40
* * * * * Case 200
* * * * * * * Range("B1").Value = 30
* * * * * Case 350
* * * * * * * Range("B1").Value = 20
* * * * * Case 400
* * * * * * * Range("B1").Value = 10
* * * * * Case Else
* * * * * * * Range("B1").Value = 0


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
change data of entire column from small case to upper case Ann Excel Worksheet Functions 1 August 16th 08 01:06 PM
Changing multiple cell text from lower case to upper case Patti Excel Discussion (Misc queries) 2 January 4th 08 08:35 PM
Change the text from lower case to upper case in an Excel work boo dave01968 Excel Discussion (Misc queries) 2 December 9th 05 09:09 AM
How do I change existing text from lower case to upper case CT Cameron Excel Discussion (Misc queries) 2 November 30th 04 01:07 AM
How to use formula auditing to change upper case to Title Case. ScoobeyDoo Excel Worksheet Functions 1 November 19th 04 06:26 PM


All times are GMT +1. The time now is 10:39 AM.

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

About Us

"It's about Microsoft Excel"