Copying number to clipboard, subtracting 398 then pasting the value to overwrite the original

Hi.

I am very new to this.

I'd be really grateful if someone could help/guide me. I want to
create a macro in Microsoft Word but I don't know visual basic.


I want to be able to highlight a number then:

- copy it to the clipboard
- subtract 298
- paste the value to the Word document, overwriting the original text
0
John
3/22/2010 11:29:43 AM
word.vba.general 1023 articles. 1 followers. Follow

3 Replies
1087 Views

Similar Articles

[PageSpeed] 40

Hi John,

There is no need to involve the clipboard if you are only changing the 
selected number. The following macro subtracts 298 from the selected number.

Sub Subtract298()
    If IsNumeric(Selection.Text) Then
        Selection.Text = Val(Selection.Text) - 298
    Else
        MsgBox "The selected text is not a number."
    End If
End Sub

Hope this helps,
Pesach Shelnitz
My Web site: http://makeofficework.com

"John" <helpme.code@yahoo.com> ??? 
??????:99a5ec97-1ee9-4d8c-904e-e14513f256e9@q16g2000yqq.googlegroups.com...
> Hi.
>
> I am very new to this.
>
> I'd be really grateful if someone could help/guide me. I want to
> create a macro in Microsoft Word but I don't know visual basic.
>
>
> I want to be able to highlight a number then:
>
> - copy it to the clipboard
> - subtract 298
> - paste the value to the Word document, overwriting the original text 


0
Pesach
3/22/2010 12:06:41 PM
John,

If the number is already highlighted in the document, then you don't need to 
copy it to the clipboard:

Sub ScratchMaco()
If IsNumeric(Selection.Text) Then
  Selection.Text = Selection.Text - 298
End If
End Sub

If there is some reason you have to put it in the clipboard, you could try:

Sub ScratchMacoII()
Dim myCopy As DataObject
Dim myPaste As DataObject
'Must have a reference to Microsoft Forms 2.0 Object Library enabled
Dim myRng As Range
If IsNumeric(Selection.Text) Then
  Set myCopy = New DataObject
  myCopy.SetText Selection.Text - 298
  myCopy.PutInClipboard
  Set myPaste = New DataObject
  myPaste.GetFromClipboard
  Selection.Text = myPaste.GetText(1)
End If
End Sub



John wrote:
> Hi.
>
> I am very new to this.
>
> I'd be really grateful if someone could help/guide me. I want to
> create a macro in Microsoft Word but I don't know visual basic.
>
>
> I want to be able to highlight a number then:
>
> - copy it to the clipboard
> - subtract 298
> - paste the value to the Word document, overwriting the original text 


0
Greg
3/22/2010 12:09:55 PM
On Mar 22, 12:06=A0pm, "Pesach Shelniitz" <pesac...@hotmail.com> wrote:
> Hi John,
>
> There is no need to involve the clipboard if you are only changing the
> selected number. The following macro subtracts 298 from the selected numb=
er.
>
> Sub Subtract298()
> =A0 =A0 If IsNumeric(Selection.Text) Then
> =A0 =A0 =A0 =A0 Selection.Text =3D Val(Selection.Text) - 298
> =A0 =A0 Else
> =A0 =A0 =A0 =A0 MsgBox "The selected text is not a number."
> =A0 =A0 End If
> End Sub
>
> Hope this helps,
> Pesach Shelnitz
> My Web site:http://makeofficework.com
>
> "John" <helpme.c...@yahoo.com> ???
> ??????:99a5ec97-1ee9-4d8c-904e-e14513f25...@q16g2000yqq.googlegroups.com.=
...
>
> > Hi.
>
> > I am very new to this.
>
> > I'd be really grateful if someone could help/guide me. I want to
> > create a macro in Microsoft Word but I don't know visual basic.
>
> > I want to be able to highlight a number then:
>
> > - copy it to the clipboard
> > - subtract 298
> > - paste the value to the Word document, overwriting the original text

Wow, thank you so much. It worked! :-)

0
John
3/22/2010 12:40:12 PM
Reply:

Similar Artilces:

How do I add % of values to stacked graph in Excel?
I have a stacked bar graph with two values on each bar, established and new patient visits. I want to add the percentage of new visits out of the total visits (new +established to the graph). Same for established. How do I do this? Use the chart labeller add-in from www.appspro.com best wishes -- Bernard V Liengme www.stfx.ca/people/bliengme remove caps from email "kataamy" <kataamy@discussions.microsoft.com> wrote in message news:E315A1B9-70F2-4B17-ABCE-AFB2CADB2A51@microsoft.com... >I have a stacked bar graph with two values on each bar, established and new > ...

Trying to create a requisition form that returns values
I am trying to create a requisition form that will allow users to enter quantities next to items in a database and return quantities and lookup values on a requistion form if the item was selected. Can someone point me in the right direction what type functions would do this? Thanks, -- Tim in Kennesaw VLOOKUP formulas will pull the data to appropriate cells. See Debra Dalgleish's site for more on VLOOKUP and Data Validation lists for entering the choices. http://www.contextures.on.ca/xlFunctions02.html http://www.contextures.on.ca/xlDataVal01.html Note the section on using DV l...

Dynamic Value in Workflows
Hello, I am creating some workflows and I want to set a value in an Account Entity based on a value in the Opportunity Entity. I believe I should be able to use the Dynamic value wizard within Workflow manager - i.e. select Account and the filed and select = and then go to Dynamic Value and select Opportunity and the field that I want the value to inherit on change of status. However when I do this I can only select Account within the Dynamic Value picklist. Any ideas? Dynamic Values are only available to children of Parent entities. Since Accounts are at the top of the CRM food c...

PO numbers in FRx?
Hello: Can FRx transaction detail reports in drill-down viewer for income statements display PO numbers from GP Purchase Order Processing, or does FRx not get that detailed? childofthe1980s FRx can bring in the originating master number of a transaction, however, I cannot think of a case where the PO number will be the originating master number, since the PO itself is not an accounting transaction. So I think you'll be able to see the receipt and/or vendor invoice numbers there, but not the PO number. -- Victoria Yudin Dynamics GP MVP Flexible Solutions - home of GP Reports htt...

Random Number in Query
Hi. I am trying to get a Random number between 0 and 5 to appear on each row of a query. I can get the same number on each row (it changes every time I run the query) but cannot get a different random number for each row. Basically, I want to create some Test data by adding the Random number to a Received Date and then saving this new date as a Completed Date. I have created a Module to generate a Random number: Function Random_Number() As Integer Randomize Random_Number = Int(Rnd * 6) End Function Then, I call the function from a query: Field = Number: Random_Number() Ca...

Why my default number format changed
I am using Excel 2007. From time to time, I found the default number format changed when I open an exiting excel file. For example, originally its default format was "General", but when I open the file, found it changed to "Custom". How is it happened? How can I prevent? How can I fix it. Thanks in advance! ...

Text to numbers
For years and years, I have been happily using Excel 97 to copy data from a website to my Excel spreadsheet by saving it as an Excel Workbook. I then manipulate the data (multiply, divide etc) without a problem. I have just installed Office 2000 Small Business, and when I try the same copy procedure, all the calculations return #VALUE. It appears that the "imported" data is text (?), with spaces. Not sure though. I realise I haven't explained this too well, but I'm hoping someone can interpret what I am trying to say, and assist. Try selecting the columns with th...

outline won't number after hitting return
I've set up the document per Shauna Kelly's instructions, but can't figure out why it won't continue to number the outline. It'll give me Heading 1, but when I hit return it goes back to "normal". What in the world am I doing wrong? You would need to modify the Heading 1 style so that it is followed by Heading 1 style (though that is not what would normally be wanted as a heading is normally followed by some text. -- Hope this helps, Doug Robbins - Word MVP Please reply only to the newsgroups unless you wish to obtain my services on a pai...

Copy from one publisher document to another
I am trying to help my father. He has created a bunch of individual publisher documents that he is now copying and pasting into one publisher document with multiple pages (he didn't know he could add pages originally). We are doing this by opening publisher twice and selecting all of an individual page and then copying. We then paste it into a blank page in the new multiple page publication. Our problem is that when we paste the items don't always land centered on the new page. Can anyone help us with this? My dad had Publisher 2003. Thanks, Barbara Select all, Cntrol A, then ...

AutoFill Changing Wrong Value
I'm trying to create an analysis sheet that gathers data from 100 worksheets within the same workbook. I want the same cell reference in each sheet, but to change the sheet number in each cell. The worksheets are named 1 - 100 Here is the formula: ='1'!B3:E3 It changes the cell references only, not the worksheets. I've changed the formula to keep the cell references: ='1'!$B$3:$E$3 I now need the formula to increment the sheet number each time, PLEASE!!! Thanks, Lisa Presumably you want to sum data from that range? Try this: =3DSUM(INDIR...

[External Copy or SYLK] file format is not valid
I am moving to a new computer. I have WIN98SE on my old computer and WIN XP on the new one. I have Excel 97 and I am trying to transfer my data to the new computer. I get the above message when I try to open a file in XP. What is the problem? Thanks in advance, Bill. ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~ View and post usenet messages directly from http://www.ExcelForum.com/ ...

which table Picklist integer value stored?
Hi there, Which database table pick list interger values stored? thanks Kyaw this query will list all the pick list integervalues and attribute name select AttributeName,AttributeValue,Value from StringMap // for account WHERE (StringMap.ObjectTypeCode=1) //for contact WHERE (StringMap.ObjectTypeCode=2) attributename will tell u about the name of the picklist attribute value is the intigers and values are what u can see on the form i think this will help u ...

How set totals of various cells with per colour fill value?
I have a sheet containing values as follows. April May June company 1 43 company 2 5 company 3 17 The cell values are also coured to indice a status. Somewhere beside the table I want to mention the totals of the cells, per status (so per colour). How to perform the latter? Thank you. Bart Excell 2003 See http://www.xldynamic.com/source/xld.ColourCounter.html for a working solution -- HTH Bob Phillips (remove xxx from email address if mailing direct) "AA Arens" <bartvandongen@gmail.com> wrote in mes...

Bin OverWrite Issue
I REALLY need HQ to NOT overwrite bin locations on the Stores... Each store has its own set of locations, and i NEED that to work! Can anyone recommend a fix or a company that could fix this for me? Can I hire someone to program something special for me? Jessica, If you are interested in looking for a solution for your problem I would love to help. We'd be happy to help you figure out a way to prevent this from happening, and if necessary we can offer a custom solution. If you are interested please give me a call at 1-888-267-RITE or drop me an email at rsakry@rite.us. -- Tha...

Getting the "name=" (bit, picklist) value that is returned from SOAP
Hi all, I am getting several fields via a Web service request in javascript in an OnChange event to poulate other field on a case. One of those fields is a bit, and one is a picklist. Those nodes in the response come back with <attribute="new_active" name="true">1</attribute> for the bit field and <attribute="status" name="On Hold">3</attribute> How can I read the name value? I've tried selectSingleNode("//status").name with no luck. Thanks! I am doing a similar process, using a SOAP response message. I ge...

How do I sum values that may contain "#N/A" in Excel?
=SUMIF(Range,"<>#N/A") or remove the cause that give the #N/A result =IF(ISNA(A2),"",A2) -- Regards, Peo Sjoblom "bakerbabe" <bakerbabe@discussions.microsoft.com> wrote in message news:6234E075-3C49-4182-83CB-23CCB10186C3@microsoft.com... > =SUM(IF(ISNA(D1:D5),0,D1:D5)) enter as an array formulas - use SHIFT+CTRL+ENTER -- Bernard V Liengme www.stfx.ca/people/bliengme remove caps from email "bakerbabe" <bakerbabe@discussions.microsoft.com> wrote in message news:6234E075-3C49-4182-83CB-23CCB10186C3@microsoft.com... >...

Copying a sheet fails
I have a line that copies a sheet from one book to another. It works a number of times in my macro then inexplicably stops working. The line is: ActiveSheet.Copy Before:=Workbooks(NewBookName).Sheets("XXX") And I get the error: 1004 "Copy method of worksheet class failed" It stops when I try to add the 54th sheet in a workbook - I don't know if that number is significant. There is no problem with the string: 'NewBookName' or the sheet named 'XXX' (as I say the line works 52 times) But suddenly I get an error Anyone seen this bef...

Prevent Copying of Excel Workbooks in 2000 and 2003.
Is there a way of preveting a user to copy an excel workbook to a different folder location? We have excel spreadsheets saved in our company network and the locations are the one safe source of information. These workbooks contain data which is linked to other workbooks so it is importnat the files are not renamed nor moved to a different folder. No matter how much I communicate this, some people insist on doing it. I know there is VBA code which can disable the use of 'Save-As' so that the files cannot be saved in a different location. However this does not prevent ...

number grab
Hi I've been a bit stupid. I have about 6 columns of price data where column R is a net selling price. I've entered these column R numbers as fixed numbers. This is my mistake because I've added a formula to the P column which knocks a percentage off the R column number to give me my purchase price. What I should have done was to have the fixed numbers in the purchase price column P for the selling price column R to derive values using a formula. The other way round in other words. I really don't want to have to work through 650 lines making a note of all the formula dete...

Counting Different Values
Well here we go, i have coloum B which has the name of the person and column F has the number now i want to have a summary page which has : Name & Number from the other page counted up. For Example: Robert Smith 10 Robert Smith XX Jim Smith 10 Jim Cox 10 Jim Cox XX Jim Cox 10 and on the summary page it has: Robert Smith - 10 Total: 1 Robert Smith - XX Total: 1 J...

Copy Posts from one Public Folder to Another
I have an Exchange 2003 Public folder tree that has multiple levels. I have a need for users to Post to one public folder and then have a copy of that Post copied to another public folder automatically. I have set this up for emails (plain forwarding) and it works fine but I have yet been able to get the Posts to duplicate to the other folder. Does anyone have any ideas? Your help is greatly appreciated. Thanks Glenn There are two ways to forward email out of a public folder: 1. Used a rule on the public folder. As owner of the public folder go to properties and to the folder assistant ...

Hiding Returned Value of hlookup
Okay, this is a tough one... (At least for me) I'm using the hlookup formula to import the starting times and ending times of employees on a daily assignment sheet. I'm compiling all the times onto a weekly schedule where each individual's hours for the week are added up. Now, I've done all this, but I get #NA when a particular employee is not on a certain day. I'm currently using IF and ISERROR to convert the #NA to "0", which allows the sheet to properly add up the hours being used by each employee. Now, I need to be able to hide the zeros so I can pri...

Help with counting values that have different endings
Hi guys, i just joined SQLMONSTER and was wondering if you guys can help me with this problem... I have 10 columns and 8,000,000 rows which have stock ticker names and exchange tickers-like the following: [Column A] AQR.L GDY.LS NBAE.LS (blank) 0023CA.S FOR.L AQR.KZ ... ... How do I find the number of unique ticker names in my database and disregard the .L, .LS, .S, .L, .KZ endings (because I am looking for the unique tickers, not the exchange). I.E., I want the values counted to be only AQR, GDY, NBAE, 0023CA, FOR or 5 values (I don't want AQR to be counted twice becau...

Paste method faile (activesheet.paste)
Hi, While using Activesheet.Paste in a newly created book through workbook.add function, I got following message "Paste method of workbook class failed." To my amazement, the same was working perfectly in MS EXCEL XP but when upgraded to Excel 2003 its creating problem.. Any idea.? Maybe adding... msgbox application.cutcopymode before you do the paste would tell you if there's anything copied that can be pasted. If there isn't anything to paste, sometimes just rearranging the order can help. dim rngtocopy as range dim newwks as worksheet with worksheets("she...

Soft copy of training material
Hi all, I have completed the class room training of CRM 3.0 Installatio and Customization. I also got the printed training material. But soetimes, searching something in the book becomes very difficult. Can I have the soft copy of these training manuals? Does Microsoft provides it? We are Gold certified partners btw. If anybody has some idea about this, please let me know. Thanks, -Imran https://dynamics.microsoftelearning.com/eLearning should find everything from your course in the eLearning Courses (or at least, I'd presume so). Either way, the online courses are a handy thing ...