LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Formatting Cell Based on Text in Column Beside It - Round 2

Hi Steve
so you want to change column G if column H contains the value 'HR'.
Change your macro to
Sub ChangingCredit()
'
Dim credit As String
dim rng as range
dim cell as range
set rng = range("H7:H17") 'range to be searched - adapt to your
needs
for each cell in range
if cell.value = "CR" then
cell.offset(0,-1).value = cell.offset(0,-1).value*(-1)
end if
next
End Sub


No need for activating and selecting cells

--
Regards
Frank Kabel
Frankfurt, Germany

Steve wrote:
I got help a week or so ago on some VBA for a routine where I needed
to change the number in a cell to a negative number based on the
content of the cell to its right. However, after I copied it into VBA
it will not work. I've changed the range ID on both but the only
effect I've had is for it to change some cells to negative and it
appears to be random at best. Here's an example of the data

G H

169.00 CR
241.30
0.14 CR
2276.00

For example I have a column of numbers and in the column directly to
the right are cells with the letters "CR" for credit. What I want to
do is to change the numbers to a negative if CR is in the cell to its
right. Below is the code I received.

Sorry for my ignorance on VBA. I'm okay with formulas, but just now
learning how to better use macros, much less write VBA. Maybe I just
don't understand what my ranges are, all I know is that I can't get
it to work.

Thanks...steve

Sub ChangingCredit()
'
Dim credit As String

Range("C7").Select 'starting point

Do Until x = 10 'Change number for extra number of blanks between
data rng = ActiveCell
credit = ActiveCell.Offset(0, 1).Range("A1").Value
'assuming Cr right of number If credit = "CR" Then
ActiveCell.Value = rng * -1
End If
ActiveCell.Offset(1, 0).Select
x = x + 1
Loop
End Sub


 
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
Conditional Formatting based on text in another cell Dave Eade Excel Discussion (Misc queries) 1 January 23rd 09 03:59 PM
Conditional formatting based off cell with text? (i.e. "less than MikeV Excel Discussion (Misc queries) 3 February 13th 08 10:02 PM
Conditional formatting Based on cell A text with conditions in Cell B Raicomm Excel Discussion (Misc queries) 0 January 21st 08 04:46 PM
Conditional Formatting based on text within a cell w/ text AND num Shirley Excel Worksheet Functions 2 December 22nd 06 01:40 AM
Deleting Rows based on text in cell & formatting cell based on text in column beside it Steve Excel Programming 4 February 26th 04 03:31 PM


All times are GMT +1. The time now is 10:50 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"