Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2008

Tip: Looking for answers? Try searching our database.

Using Case and referencing a cell instead of a value

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
S Himmelrich - 16 Jan 2008 21:56 GMT
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
carlo - 17 Jan 2008 00:14 GMT
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

> 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
[quoted text clipped - 14 lines]
>           Case Else
>               Range("B1").Value = 0
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.