Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Trouble with code

I'm using this code to force specific cells in my open spreadsheet to a
negative value. I'm getting an error half way through the code. It is
making the values in cells B109, B113, B65, B66, B68, B69, B71, B72 and G7
negative but errors before looking at the remaining stated cells. Can
anybody help me in fixing this code. Thank you,

Sub ForceCellsToNegative()

Dim Rng As Range
Dim rCell As Range

Set Rng =
Range("B109,B113,B65,B66,B68,B69,B71,B72,G7:G12,G2 4:G35,G37:G48,G50:G61,G81:G83,G86:G105,G107,G108,G 111,G112")

For Each rCell In Rng.Cells
With rCell
If .Value < "" Then
..Value = -Abs(.Value)
..Font.Name = "Arial"
..Font.Bold = True
..NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
End If
If Not Rng Is Nothing Then

Else
Exit Sub
End If

End With
Next rCell

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Trouble with code

Sub ForceCellsToNegative()

Dim Rng As Range
Dim rCell As Range

Set Rng =
Range("B109,B113,B65,B66,B68,B69,B71,B72,G7:G12,G2 4:G35,G37:G48,G50:G61,G81:G83,G86:G105,G107,G108,G 111,G112")

For Each rCell In Rng.Cells
With rCell
If isnumeric(.Value) Then
.Value = -Abs(.Value)
.Font.Name = "Arial"
.Font.Bold = True
.NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
End If

End With
Next rCell

End Sub

--
Regards,
Tom Ogilvy

"JOUIOUI" wrote:

I'm using this code to force specific cells in my open spreadsheet to a
negative value. I'm getting an error half way through the code. It is
making the values in cells B109, B113, B65, B66, B68, B69, B71, B72 and G7
negative but errors before looking at the remaining stated cells. Can
anybody help me in fixing this code. Thank you,

Sub ForceCellsToNegative()

Dim Rng As Range
Dim rCell As Range

Set Rng =
Range("B109,B113,B65,B66,B68,B69,B71,B72,G7:G12,G2 4:G35,G37:G48,G50:G61,G81:G83,G86:G105,G107,G108,G 111,G112")

For Each rCell In Rng.Cells
With rCell
If .Value < "" Then
.Value = -Abs(.Value)
.Font.Name = "Arial"
.Font.Bold = True
.NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
End If
If Not Rng Is Nothing Then

Else
Exit Sub
End If

End With
Next rCell

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Trouble with code

Hi Tom,

Thanks for helping me. Now this code adds $0.00 values in those cells that
are empty. I only want those cells that have a value to be forced to
negative. How can we alter this code to skip past empty cells in the
specificed range. Thanks again.

"Tom Ogilvy" wrote:

Sub ForceCellsToNegative()

Dim Rng As Range
Dim rCell As Range

Set Rng =
Range("B109,B113,B65,B66,B68,B69,B71,B72,G7:G12,G2 4:G35,G37:G48,G50:G61,G81:G83,G86:G105,G107,G108,G 111,G112")

For Each rCell In Rng.Cells
With rCell
If isnumeric(.Value) Then
.Value = -Abs(.Value)
.Font.Name = "Arial"
.Font.Bold = True
.NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
End If

End With
Next rCell

End Sub

--
Regards,
Tom Ogilvy

"JOUIOUI" wrote:

I'm using this code to force specific cells in my open spreadsheet to a
negative value. I'm getting an error half way through the code. It is
making the values in cells B109, B113, B65, B66, B68, B69, B71, B72 and G7
negative but errors before looking at the remaining stated cells. Can
anybody help me in fixing this code. Thank you,

Sub ForceCellsToNegative()

Dim Rng As Range
Dim rCell As Range

Set Rng =
Range("B109,B113,B65,B66,B68,B69,B71,B72,G7:G12,G2 4:G35,G37:G48,G50:G61,G81:G83,G86:G105,G107,G108,G 111,G112")

For Each rCell In Rng.Cells
With rCell
If .Value < "" Then
.Value = -Abs(.Value)
.Font.Name = "Arial"
.Font.Bold = True
.NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
End If
If Not Rng Is Nothing Then

Else
Exit Sub
End If

End With
Next rCell

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Trouble with code

If isnumeric(.Value) Then

should only work on the cell if it contains a number.

--
Regards,
Tom Ogilvy



"JOUIOUI" wrote:

Hi Tom,

Thanks for helping me. Now this code adds $0.00 values in those cells that
are empty. I only want those cells that have a value to be forced to
negative. How can we alter this code to skip past empty cells in the
specificed range. Thanks again.

"Tom Ogilvy" wrote:

Sub ForceCellsToNegative()

Dim Rng As Range
Dim rCell As Range

Set Rng =
Range("B109,B113,B65,B66,B68,B69,B71,B72,G7:G12,G2 4:G35,G37:G48,G50:G61,G81:G83,G86:G105,G107,G108,G 111,G112")

For Each rCell In Rng.Cells
With rCell
If isnumeric(.Value) Then
.Value = -Abs(.Value)
.Font.Name = "Arial"
.Font.Bold = True
.NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
End If

End With
Next rCell

End Sub

--
Regards,
Tom Ogilvy

"JOUIOUI" wrote:

I'm using this code to force specific cells in my open spreadsheet to a
negative value. I'm getting an error half way through the code. It is
making the values in cells B109, B113, B65, B66, B68, B69, B71, B72 and G7
negative but errors before looking at the remaining stated cells. Can
anybody help me in fixing this code. Thank you,

Sub ForceCellsToNegative()

Dim Rng As Range
Dim rCell As Range

Set Rng =
Range("B109,B113,B65,B66,B68,B69,B71,B72,G7:G12,G2 4:G35,G37:G48,G50:G61,G81:G83,G86:G105,G107,G108,G 111,G112")

For Each rCell In Rng.Cells
With rCell
If .Value < "" Then
.Value = -Abs(.Value)
.Font.Name = "Arial"
.Font.Bold = True
.NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
End If
If Not Rng Is Nothing Then

Else
Exit Sub
End If

End With
Next rCell

End Sub

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
Trouble with Code, but only sometimes JOUIOUI Excel Programming 0 December 15th 06 01:18 PM
Trouble with this code JOUIOUI Excel Programming 3 November 7th 06 12:35 AM
Trouble with this code JOUIOUI Excel Programming 4 June 11th 06 04:49 PM
Trouble Condensing Code Ikaabod Excel Programming 3 April 11th 06 09:53 PM
Print dialog code trouble Tim[_36_] Excel Programming 1 April 18th 04 08:46 AM


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