Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Find Text and put total across from it

I have the following code:

Sub UpdateTotal()
'
' UpdateTotal Macro
' Macro recorded 3/23/2005 by Stacey Macumber
'
' Keyboard Shortcut: Ctrl+u
'
Dim dblSum As Double
Dim cell As Range
On Error GoTo Errhandler:
dblSum = 0
With ActiveSheet
For Each cell In .Range("e1:e5000")
If cell.Interior.ColorIndex = 16 Then
dblSum = dblSum + cell.Offset(0, 0).Value
End If
Next
Application.EnableEvents = False

.Range("A2917").Value = dblSum
.Range("A2917").Activate

Application.EnableEvents = True
End With
Errhandler:
Application.EnableEvents = True
End Sub

Where the line .Range("A2917").Value = dblSum instead I want the macro to
look for the word TOTAL and then place the .Value on the same row but 5
columns over, the reason for this is TOTAL can be on a different row each
time the report is ran so I can't do the set thing "A2917" like I have been
(by just changing the cell as needed).
I haven't been very success with trying other code.

Any help would be great!
  #2   Report Post  
Posted to microsoft.public.excel.programming
ben ben is offline
external usenet poster
 
Posts: 232
Default Find Text and put total across from it

smac,
replace both .value = and the .activate code with this code


dim totalr as range
set totalr = cells.find _(what:="TOTAL", _
lookin:=xlvalues, lookat:=xlwhole,matchcase:=true)
if totalr is nothing then
msgbox "Could not find TOTAL"
exit sub
end if
totalr.activate
activecell.offset(0,5).value = dblsum


ben


"SMac" wrote:

I have the following code:

Sub UpdateTotal()
'
' UpdateTotal Macro
' Macro recorded 3/23/2005 by Stacey Macumber
'
' Keyboard Shortcut: Ctrl+u
'
Dim dblSum As Double
Dim cell As Range
On Error GoTo Errhandler:
dblSum = 0
With ActiveSheet
For Each cell In .Range("e1:e5000")
If cell.Interior.ColorIndex = 16 Then
dblSum = dblSum + cell.Offset(0, 0).Value
End If
Next
Application.EnableEvents = False

.Range("A2917").Value = dblSum
.Range("A2917").Activate

Application.EnableEvents = True
End With
Errhandler:
Application.EnableEvents = True
End Sub

Where the line .Range("A2917").Value = dblSum instead I want the macro to
look for the word TOTAL and then place the .Value on the same row but 5
columns over, the reason for this is TOTAL can be on a different row each
time the report is ran so I can't do the set thing "A2917" like I have been
(by just changing the cell as needed).
I haven't been very success with trying other code.

Any help would be great!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Find Text and put total across from it

Works like a charm!

"ben" wrote:

smac,
replace both .value = and the .activate code with this code


dim totalr as range
set totalr = cells.find _(what:="TOTAL", _
lookin:=xlvalues, lookat:=xlwhole,matchcase:=true)
if totalr is nothing then
msgbox "Could not find TOTAL"
exit sub
end if
totalr.activate
activecell.offset(0,5).value = dblsum


ben


"SMac" wrote:

I have the following code:

Sub UpdateTotal()
'
' UpdateTotal Macro
' Macro recorded 3/23/2005 by Stacey Macumber
'
' Keyboard Shortcut: Ctrl+u
'
Dim dblSum As Double
Dim cell As Range
On Error GoTo Errhandler:
dblSum = 0
With ActiveSheet
For Each cell In .Range("e1:e5000")
If cell.Interior.ColorIndex = 16 Then
dblSum = dblSum + cell.Offset(0, 0).Value
End If
Next
Application.EnableEvents = False

.Range("A2917").Value = dblSum
.Range("A2917").Activate

Application.EnableEvents = True
End With
Errhandler:
Application.EnableEvents = True
End Sub

Where the line .Range("A2917").Value = dblSum instead I want the macro to
look for the word TOTAL and then place the .Value on the same row but 5
columns over, the reason for this is TOTAL can be on a different row each
time the report is ran so I can't do the set thing "A2917" like I have been
(by just changing the cell as needed).
I haven't been very success with trying other code.

Any help would be great!

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
find common text in cell in column in sheet then return total amou leeona Excel Worksheet Functions 1 June 7th 08 04:43 AM
I have a sub total need to find the GST & QST any formula music icons Excel Worksheet Functions 3 September 9th 07 04:26 PM
find text in column h and total the corresponding numbers if colum adelaide Excel Discussion (Misc queries) 2 February 6th 06 04:47 AM
function to find which cells add up to a given total? jbourgui Excel Worksheet Functions 6 August 12th 05 08:17 PM
find parts of a total Jim Excel Worksheet Functions 1 February 22nd 05 08:07 PM


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