Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Selecting Cells With Sumproduct Formula, Then Pasting Its Value Over Top

Hello,

In testing, I tried the formula below without success. Basically, I
was trying to select only those cells within a range that contained the
function SUMPRODUCT. After selecting all instances where this is true,
I want to copy/paste the actual value of the result of that formula
over top of the formula. I have other formulas in my spreadsheet that
do not use SUMPRODUCT, but I don't want to touch those.

It appears that ActiveCell.Value is the value that the function
returns, not the formula itself, so I know that this doesn't help me,
but I couldn't find another property for ActiveCell that would make it
work.

Ultimately, I want to include multiple sheets in my search, so if you
know code where I can do it all in one fell swoop, that would be great.

Any ideas out there?

Sub Test()
Dim SearchString, SearchSubstr, MyPos
Worksheets("Receipts-Initial").Activate
SearchSubstr = "SUMPRODUCT"
For Each Cell In Worksheets("Receipts-Initial").Range("A16:Q16")
SearchString = ActiveCell.Value
MyPos = InStr(1, SearchString, SearchSubstr, 1)
If MyPos < 0 Then
ActiveCell.Select
End If
Next
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
End Sub

Thanks,
Carroll Rinehart

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Selecting Cells With Sumproduct Formula, Then Pasting Its Value Over Top

Sub Test()
Dim SearchString, SearchSubstr, MyPos
Worksheets("Receipts-Initial").Activate
SearchSubstr = "SUMPRODUCT"
For Each Cell In Worksheets("Receipts-Initial").Range("A16:Q16")
SearchString = ActiveCell.Formula
MyPos = InStr(1, SearchString, SearchSubstr, vbTextCompare)
If MyPos < 0 Then
ActiveCell.Formula = ActiveCell.Value
End If
Next
End Sub

--
Regards,
Tom Ogilvy

"Carroll" wrote in message
oups.com...
Hello,

In testing, I tried the formula below without success. Basically, I
was trying to select only those cells within a range that contained the
function SUMPRODUCT. After selecting all instances where this is true,
I want to copy/paste the actual value of the result of that formula
over top of the formula. I have other formulas in my spreadsheet that
do not use SUMPRODUCT, but I don't want to touch those.

It appears that ActiveCell.Value is the value that the function
returns, not the formula itself, so I know that this doesn't help me,
but I couldn't find another property for ActiveCell that would make it
work.

Ultimately, I want to include multiple sheets in my search, so if you
know code where I can do it all in one fell swoop, that would be great.

Any ideas out there?

Sub Test()
Dim SearchString, SearchSubstr, MyPos
Worksheets("Receipts-Initial").Activate
SearchSubstr = "SUMPRODUCT"
For Each Cell In Worksheets("Receipts-Initial").Range("A16:Q16")
SearchString = ActiveCell.Value
MyPos = InStr(1, SearchString, SearchSubstr, 1)
If MyPos < 0 Then
ActiveCell.Select
End If
Next
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
End Sub

Thanks,
Carroll Rinehart



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Selecting Cells With Sumproduct Formula, Then Pasting Its Value Over Top

Tom,

I'm finding that the SearchString ends up being the value that the
function returns rather than the function itself, so MyPos is always
equal to 0, so it ends up doing nothing.

Carroll

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Selecting Cells With Sumproduct Formula, Then Pasting Its Value Over Top

Also, I notice with a Debug.Print ActiveCell.Address thrown into the
for..next loop, that the active cell actually never changes, so I'm
guessing that this approach won't work.

Carroll

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Selecting Cells With Sumproduct Formula, Then Pasting Its Value Over Top

I figured out what was wrong. Instead of saying ActiveCell.Formula and
ActiveCell.Value, I should be using Cell.Formula and Cell.Value. I
guess when you're in a For Each...Next loop, ActiveCell never changes,
but you have to reference what cell it's on in the range by using just
the word "Cell".

Thanks Tom for giving me some guidance here.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Selecting Cells With Sumproduct Formula, Then Pasting Its Value Over Top

I had not really looked at your loop, but focused on the specifics of your
question. You are correct that the active cell would not change unless you
did

Sub Test()
Dim SearchString, SearchSubstr, MyPos
Worksheets("Receipts-Initial").Activate
SearchSubstr = "SUMPRODUCT"
For Each Cell In Worksheets("Receipts-Initial").Range("A16:Q16")
cell.Activate
SearchString = ActiveCell.Formula
MyPos = InStr(1, SearchString, SearchSubstr, vbTextCompare)
If MyPos < 0 Then
ActiveCell.Formula = ActiveCell.Value
End If
Next
End Sub

but not activating the cell is the preferred method so If I had looked at
your code a little more closely, I would have suggested

Sub Test()
Dim SearchSubstr as String, Cell as Range
SearchSubstr = "SUMPRODUCT"
For Each Cell In Worksheets("Receipts-Initial").Range("A16:Q16")
If InStr(1, cell.formula, SearchSubstr, vbTextCompare) then
Cell.Formula = Cell.Value
End If
Next
End Sub

--
Regards,
Tom Ogilvy


"Carroll" wrote in message
oups.com...
I figured out what was wrong. Instead of saying ActiveCell.Formula and
ActiveCell.Value, I should be using Cell.Formula and Cell.Value. I
guess when you're in a For Each...Next loop, ActiveCell never changes,
but you have to reference what cell it's on in the range by using just
the word "Cell".

Thanks Tom for giving me some guidance here.



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
pasting same data over many cells containing a formula Todd[_2_] Excel Worksheet Functions 4 April 18th 08 06:13 PM
Selecting & Pasting Dynamic Ranges GerryM[_2_] Excel Programming 4 November 17th 04 09:12 AM
Selecting and pasting to an empty cell Craig from MI Excel Programming 1 March 7th 04 06:36 AM
Help - Selecting and pasting into range amonymous Excel Programming 4 January 21st 04 12:21 AM
Selecting cells with a particular formula Muusbreath Excel Programming 1 October 30th 03 04:52 PM


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