ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro - If bold then multiply by -1 (https://www.excelbanter.com/excel-programming/390417-macro-if-bold-then-multiply-1-a.html)

[email protected][_2_]

Macro - If bold then multiply by -1
 
Hi there

I have number in column A

What I want to do is have a macro that can look down the column and if
the cell is bold then multiply the contents by -1 in order for me to
turn it into a negative figure.

I someone can help with this,

Thanks

Andrea


WhytheQ

Macro - If bold then multiply by -1
 
dim myCell
for each myCell in activesheet.columns(1).cells
if myCell < "" then
if mycell.font.fontstyle = "Bold" then
on error resume next 'just incase there is text in
the cell
myCell = myCell*-1
end if
end if
next myCell

.....not tested but hopefully the above is a good start for you

J


On 31 May, 11:44, "
wrote:
Hi there

I have number in column A

What I want to do is have a macro that can look down the column and if
the cell is bold then multiply the contents by -1 in order for me to
turn it into a negative figure.

I someone can help with this,

Thanks

Andrea




WhytheQ

Macro - If bold then multiply by -1
 
just tested and looks like you need to use the following line rather
than what I originally said:

myCell.Value = myCell.Value * -1

(I thought value was the default property !!)

J



On 31 May, 11:52, WhytheQ wrote:
dim myCell
for each myCell in activesheet.columns(1).cells
if myCell < "" then
if mycell.font.fontstyle = "Bold" then
on error resume next 'just incase there is text in
the cell
myCell = myCell*-1
end if
end if
next myCell

....not tested but hopefully the above is a good start for you

J

On 31 May, 11:44, "



wrote:
Hi there


I have number in column A


What I want to do is have a macro that can look down the column and if
the cell is bold then multiply the contents by -1 in order for me to
turn it into a negative figure.


I someone can help with this,


Thanks


Andrea- Hide quoted text -


- Show quoted text -




Bob Phillips

Macro - If bold then multiply by -1
 

Public Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Dim i As Long
Dim iLastRow As Long
With ActiveSheet

iLastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = 1 To iLastRow
If .Cells(i, TEST_COLUMN).Font.Bold Then
If IsNumeric(.Cells(i, TEST_COLUMN).Value) Then
.Cells(i, TEST_COLUMN).Value = .Cells(i,
TEST_COLUMN).Value * -1
End If
End If
Next i

End With

End Sub


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

wrote in message
oups.com...
Hi there

I have number in column A

What I want to do is have a macro that can look down the column and if
the cell is bold then multiply the contents by -1 in order for me to
turn it into a negative figure.

I someone can help with this,

Thanks

Andrea




Bob Phillips

Macro - If bold then multiply by -1
 
Beware word-wrap

Public Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Dim i As Long
Dim iLastRow As Long
With ActiveSheet

iLastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = 1 To iLastRow
If .Cells(i, TEST_COLUMN).Font.Bold Then
If IsNumeric(.Cells(i, TEST_COLUMN).Value) Then
.Cells(i, TEST_COLUMN).Value = _
.Cells(i, TEST_COLUMN).Value * -1
End If
End If
Next i

End With

End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Bob Phillips" wrote in message
...

Public Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Dim i As Long
Dim iLastRow As Long
With ActiveSheet

iLastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = 1 To iLastRow
If .Cells(i, TEST_COLUMN).Font.Bold Then
If IsNumeric(.Cells(i, TEST_COLUMN).Value) Then
.Cells(i, TEST_COLUMN).Value = .Cells(i,
TEST_COLUMN).Value * -1
End If
End If
Next i

End With

End Sub


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)

wrote in message
oups.com...
Hi there

I have number in column A

What I want to do is have a macro that can look down the column and if
the cell is bold then multiply the contents by -1 in order for me to
turn it into a negative figure.

I someone can help with this,

Thanks

Andrea







All times are GMT +1. The time now is 03:42 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com