Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-16-2018, 01:42 AM
jariquelme jariquelme is offline Getting cells referenced while creating formula Windows 10 Getting cells referenced while creating formula Office 2010 32bit
Novice
Getting cells referenced while creating formula
 
Join Date: Apr 2018
Posts: 3
jariquelme is on a distinguished road
Default Getting cells referenced while creating formula

Hi.

I need to get the range selected when I create a formula for use in Interop services.

For example, if i am creating this formula =SUM(A1:A10), I select the range by mouse.

There is any Excel interop property that provides me the A1:A10 range?



TIA
Reply With Quote
  #2  
Old 04-17-2018, 01:16 AM
p45cal's Avatar
p45cal p45cal is offline Getting cells referenced while creating formula Windows 10 Getting cells referenced while creating formula Office 2010 32bit
Expert
 
Join Date: Apr 2014
Posts: 871
p45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond repute
Default

msgbox Selection.address(0,0)
?
Reply With Quote
  #3  
Old 04-17-2018, 01:28 AM
jariquelme jariquelme is offline Getting cells referenced while creating formula Windows 10 Getting cells referenced while creating formula Office 2010 32bit
Novice
Getting cells referenced while creating formula
 
Join Date: Apr 2018
Posts: 3
jariquelme is on a distinguished road
Default

Hi p45cal.

I need to know the range selected while creating the formula. Selection.Address(0,0) is only set when I accept the edition.

TIA
Reply With Quote
  #4  
Old 04-17-2018, 01:47 AM
p45cal's Avatar
p45cal p45cal is offline Getting cells referenced while creating formula Windows 10 Getting cells referenced while creating formula Office 2010 32bit
Expert
 
Join Date: Apr 2014
Posts: 871
p45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond repute
Default

Quote:
Originally Posted by jariquelme View Post
Hi p45cal.

I need to know the range selected while creating the formula. Selection.Address(0,0) is only set when I accept the edition.

TIA
I haven't the foggiest what you mean but:
Code:
range("H5").Formula = "=SUM(" & Selection.address(0,0) & ")"
Perhaps if you described th background behind what you're trying to do…
Reply With Quote
  #5  
Old 04-17-2018, 03:12 AM
jariquelme jariquelme is offline Getting cells referenced while creating formula Windows 10 Getting cells referenced while creating formula Office 2010 32bit
Novice
Getting cells referenced while creating formula
 
Join Date: Apr 2018
Posts: 3
jariquelme is on a distinguished road
Default

Hi p45cal.

The background of the process is as following:

1.- Click in one cell.
2.- Put "=SUM(" to create a SUM.
3.- Select a range to sum with mouse.
4.- Getting the selected range in an Interop property to send to another application.
5.- Hit ENTER to save the data

In other forum, Hans Vogelaar tell me that object model can not expose data in edit mode. This could be the problem.

TIA.
Reply With Quote
  #6  
Old 04-17-2018, 03:33 AM
p45cal's Avatar
p45cal p45cal is offline Getting cells referenced while creating formula Windows 10 Getting cells referenced while creating formula Office 2010 32bit
Expert
 
Join Date: Apr 2014
Posts: 871
p45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond repute
Default

It is, but do you have to do it before the formula is committed to the sheet?
You could examine the formula directly after committing it to the sheet using a Worksheet_Change event. This in the sheet concerned's code-module:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
myString = Target.Formula
MsgBox myString
If UCase(Left(myString, 5)) = "=SUM(" Then
  strRng = Split(Split(myString, "(")(1), ")")(0)
  MsgBox strRng
End If
End Sub
Not very robust but with a few more IFs perhaps could be made to do what you want.

Last edited by p45cal; 04-17-2018 at 04:36 PM.
Reply With Quote
  #7  
Old 04-17-2018, 03:12 PM
macropod's Avatar
macropod macropod is offline Getting cells referenced while creating formula Windows 7 64bit Getting cells referenced while creating formula Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Cross-posted at:
https://www.excelguru.ca/forums/show...eating-formula
https://social.msdn.microsoft.com/Fo...forum=exceldev

For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting cells referenced while creating formula Filling a formula down a column where only one cell value referenced changes? takamaz Excel 2 03-11-2018 08:56 AM
Getting cells referenced while creating formula Creating a Text Entry That Holds a Property and Can Be Referenced Elsewhere mike_302 Word 2 01-17-2018 06:03 AM
Getting cells referenced while creating formula Shorter VBA for creating borders for cells mbesspiata Excel 2 07-28-2014 12:37 PM
Formula to hide '0' from blank referenced cells formuladummy Excel 3 05-08-2014 02:33 AM
Help with creating a Formula, please websiteaog Excel 9 11-25-2010 04:09 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:57 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft