Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 396
Default Problem with Code --- Please help

Hi, i got this code very kindly from Tom and i have changed it, but it
does not work. Could you please help me ?

Sub TotalsS()
'
Dim eRowS As Long
Dim fRowS As Long
Dim LrowS As Long
Dim myValS As Long
eRowS = Cells(Rows.Count, 1).End(xlUp).Row
fRowS = 4
Do Until LrowS = eRowS + 1
LrowS = Cells(fRowS, 10).End(xlDown).Row + 1
With Cells(LrowS, 10)
.Font.Bold = True
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.NumberFormat = "R #,##0.00"
.FormulaR1C1 = _
"=SUM(R[-" & LrowS - fRowS & "]C:R[-1]C)"
With .Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Borders(xlEdgeBottom)
.LineStyle = xlDouble
.ColorIndex = xlAutomatic
End With
End With
fRowS = LrowS + 2
Loop
myValS = Cells(LrowS, 10)
With Cells(LrowS, 10)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue,
Operator:=xlGreater, Formula1:="0"
.FormatConditions(1).Interior.ColorIndex = 35
.FormatConditions.Add Type:=xlCellValue,
Operator:=xlLess, Formula1:="0"
.FormatConditions(2).Interior.ColorIndex = 38
End With
If myValS < 0 Then Cells(LrowS, 7) = "Total due to supplier"
'--Minus value
If myValS 0 Then Cells(LrowS, 7) = "Total due to BMW SA" '
--Positive value
With Cells(LrowS, 7)
.Font.Bold = True
End With
Columns("J:J").ColumnWidth = 12
Range("C4").Select
ActiveWindow.FreezePanes = True
GetSuppNameAS
End Sub


Les Stout

*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Problem with Code --- Please help

Um? What does not work? What errors do you get and what is it trying to do
?

--
Cheers
Nigel



"Les Stout" wrote in message
...
Hi, i got this code very kindly from Tom and i have changed it, but it
does not work. Could you please help me ?

Sub TotalsS()
'
Dim eRowS As Long
Dim fRowS As Long
Dim LrowS As Long
Dim myValS As Long
eRowS = Cells(Rows.Count, 1).End(xlUp).Row
fRowS = 4
Do Until LrowS = eRowS + 1
LrowS = Cells(fRowS, 10).End(xlDown).Row + 1
With Cells(LrowS, 10)
.Font.Bold = True
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.NumberFormat = "R #,##0.00"
.FormulaR1C1 = _
"=SUM(R[-" & LrowS - fRowS & "]C:R[-1]C)"
With .Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Borders(xlEdgeBottom)
.LineStyle = xlDouble
.ColorIndex = xlAutomatic
End With
End With
fRowS = LrowS + 2
Loop
myValS = Cells(LrowS, 10)
With Cells(LrowS, 10)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue,
Operator:=xlGreater, Formula1:="0"
.FormatConditions(1).Interior.ColorIndex = 35
.FormatConditions.Add Type:=xlCellValue,
Operator:=xlLess, Formula1:="0"
.FormatConditions(2).Interior.ColorIndex = 38
End With
If myValS < 0 Then Cells(LrowS, 7) = "Total due to supplier"
'--Minus value
If myValS 0 Then Cells(LrowS, 7) = "Total due to BMW SA" '
--Positive value
With Cells(LrowS, 7)
.Font.Bold = True
End With
Columns("J:J").ColumnWidth = 12
Range("C4").Select
ActiveWindow.FreezePanes = True
GetSuppNameAS
End Sub


Les Stout

*** Sent via Developersdex http://www.developersdex.com ***



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 396
Default Problem with Code --- Please help

Ooops...... sorry, forgot that part !!! It is almost like it is looping
as i get two totals at the bottom and i am supposed to only have one
total. I then get an error at what looks like the third loop of "out of
range" at this point: With Cells(LrowS, 10)


Les Stout

*** Sent via Developersdex http://www.developersdex.com ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Problem with Code --- Please help

This puts in a single total at the bottom of a column of numbers starting in
Row 4 of column 10

by the way, you said "Tom" gave you this code, but it must be a different
"Tom" than me. I only mention that because you contacted me asking for
help.

Sub TotalsS()
'
Dim eRowS As Long
Dim fRowS As Long
Dim LrowS As Long
Dim myValS As Long
eRowS = Cells(Rows.Count, 1).End(xlUp).Row
fRowS = 4
LrowS = Cells(fRowS, 10).End(xlDown).Row + 1
With Cells(LrowS, 10)
.Font.Bold = True
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.NumberFormat = "R #,##0.00"
.FormulaR1C1 = _
"=SUM(R[-" & LrowS - fRowS & "]C:R[-1]C)"
With .Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Borders(xlEdgeBottom)
.LineStyle = xlDouble
.ColorIndex = xlAutomatic
End With
End With
fRowS = LrowS + 2
myValS = Cells(LrowS, 10)
With Cells(LrowS, 10)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlGreater, Formula1:="0"
.FormatConditions(1).Interior.ColorIndex = 35
.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlLess, Formula1:="0"
.FormatConditions(2).Interior.ColorIndex = 38
End With
If myValS < 0 Then Cells(LrowS, 7) = _
"Total due to supplier" '--Minus value
If myValS 0 Then Cells(LrowS, 7) = _
"Total due to BMW SA" '--Positive value
With Cells(LrowS, 7)
.Font.Bold = True
End With
Columns("J:J").ColumnWidth = 12
Range("C4").Select
ActiveWindow.FreezePanes = True
GetSuppNameAS
End Sub

--
Regards,
Tom Ogilvy


"Les Stout" wrote in message
...
Ooops...... sorry, forgot that part !!! It is almost like it is looping
as i get two totals at the bottom and i am supposed to only have one
total. I then get an error at what looks like the third loop of "out of
range" at this point: With Cells(LrowS, 10)


Les Stout

*** Sent via Developersdex http://www.developersdex.com ***



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 396
Default Problem with Code --- Please help

Thanks for your help Tom, i thought it was you.

Thanks again for your help.

best regards,

Les Stout

*** Sent via Developersdex http://www.developersdex.com ***


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 396
Default Problem with Code --- Please help

Hi Tom, i still have a problem and i cannot figure out what it is ? If i
run this code manually using "F8" to step into and then "F5" it works
great, but if i run it whith the rest of my code it inserts two totals,
one at the botom of the column and then another after it ??

Any suggestions ?

Les Stout

*** Sent via Developersdex http://www.developersdex.com ***
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
Code problem puiuluipui Excel Discussion (Misc queries) 3 July 3rd 09 07:27 PM
Alt Code Problem aftamath77 Excel Discussion (Misc queries) 2 February 10th 09 11:42 PM
XLS to CSV Code Problem carl Excel Worksheet Functions 0 March 28th 07 01:21 AM
vba code problem sarasa[_8_] Excel Programming 0 June 15th 04 12:33 AM
Code Problem Todd Huttenstine Excel Programming 3 April 16th 04 09:25 PM


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