excel – As Seen Through PeriVision https://www.perivision.net/wordpress An Mobile centric blog ... Full of Tech goodness Thu, 03 Jul 2014 20:55:07 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.5 4666035 How to update a cell based on date in excel and store that value https://www.perivision.net/wordpress/2014/07/how-to-update-a-cell-based-on-date-in-excel-and-store-that-value/ https://www.perivision.net/wordpress/2014/07/how-to-update-a-cell-based-on-date-in-excel-and-store-that-value/#respond Thu, 03 Jul 2014 20:55:07 +0000 http://www.perivision.net/wordpress/?p=9461 Read More]]> Excel change on Date ExampleA few weeks back I was asked to create a rule in Excel that would recalculate a cell’s value ONLY on Monday!  And store that calculation. What?  Hmm..  Then I thought, wait a minute, I should be able to do this in the cells directly. At first I tried to do this all in one cell and its got pretty messy. So instead I divided it up into two steps. First convert the date to string, then a simple if statement if the string = “Mon”.
To start, put a number in cell A1. Any number. place 6/2/2014 in B2. Place a number in A8 and B8. I have these lower for a reason you will see later.

So first the date. In cell B2 I have the following.
6/2/2014
In cell B3 I wrote this..
=TEXT(B2,”ddd”) – (in the real sheet, this cell is hidden somewhere.
Ok, now I do a simple =IF statement. For those of you who do not know, here is how a simple =IF statement works.. IF(logical_test,value_if_true,value_if_false)

So in cell C8 I have the following
=IF(B3=”Mon”, A8, B8)

B3 is the string value of the date from B2. A8 is the value if its Monday, and B8 is the value of its not. Done!

But there is a problem here… The actual goal is to have the new value STAY as the new value on and after Monday until the following Monday when it gets re calculated again. Ahhh. That is MUCH harder.

So here is where doing calculation in cells break down. Because we want to retain the new value after Monday, we cannot just have a simple =IF test because on tuesday, it goes back to the old value again. the IF statement has two conditions, true or false. We need to find a way to keep the new value we calculated on Monday throughout the week and then update it again the following Monday.

So VBScript to the rescue. If you have never written a script in Excel you may want to look up a few tutorials, its pretty powerful once you get into it, however, lets just walk you through it.

First right-click on the sheet tab in your spreadsheet. In my case, I right-clicked on ‘Sheet1’

A new window will popup called Microsoft Visual Basic for Applications.

Copy and paste the following code in. We will walk through it in a sec..

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Last As Integer
Application.EnableEvents = False

Dim currDateString As String
currDateString = Range("b3").Text
If currDateString = "Mon" Then Range("C1") = Range("A1")

Application.EnableEvents = True
End Sub

This is pretty much the same thing we did with the cells earlier, however, we are going to use the magic command ‘Application.EnableEvents = False’. What this does is still Excel not to calculate anything until told otherwise. Now, lets run our if statement. Again we have this broken up into two steps.

Dim currDateString As String
currDateString = Range("b3").Text

What these two lines do is set currDateString as a varible and then assign it the string value we already have in B3. If we wanted to be fancy we could have done this in code as well, but I’m trying to keep this simple.

Next we run our simple If statement.

If currDateString = "Mon" Then Range("C1") = Range("A1")

This is pretty stright forward, if currDateString (B3) = “Mon”, then have the cell C1 = A1.

And we are done. We turn on ‘Application.EnableEvents = True’ and let Excel do its thing.

Give it a try. Change A1 while the date is set to June 2 and you will see C1 updating. Change the date, and C1 no longer updates. Close the file and then reopen and the value are where you left off.

Neat eh?

I’m sure there are cooler ways to write this but again, I was going for simple here.

Enjoy!

Share and Enjoy !

Shares
]]>
https://www.perivision.net/wordpress/2014/07/how-to-update-a-cell-based-on-date-in-excel-and-store-that-value/feed/ 0 9461
Cant cut and paste a formula in excel? Could be a skype bug https://www.perivision.net/wordpress/2012/04/cant-cut-and-paste-a-formula-in-excel-could-be-a-skype-bug/ https://www.perivision.net/wordpress/2012/04/cant-cut-and-paste-a-formula-in-excel-could-be-a-skype-bug/#respond Mon, 30 Apr 2012 21:38:23 +0000 http://www.perivision.net/wordpress/?p=7074 Read More]]> This through me for a look.  Seems that if you have a skype plugin installed, you cannot cut and paste formulas in Excel.  Pretty random till you think about it. The skype plugin is pretty aggressive trying to capture what it thinks are phone numbers and its totally possible the its intercepting the paste function and then gets confused when its a formula.  Fortunately, the fix is easy enough.

1. Open Control Panel.

2. Select Uninstall a Program under the Programs section.

3. Select Skype Click to Call, then choose Uninstall.

Once uninstalled, you may have to close and relaunch Excel. The problem pasting formulas should now be resolved.

Uninstalling Skype Click to Call

Credit Mitch Bartlett for this one.

Share and Enjoy !

Shares
]]>
https://www.perivision.net/wordpress/2012/04/cant-cut-and-paste-a-formula-in-excel-could-be-a-skype-bug/feed/ 0 7074
How to make Excel open each file in a separate window. Tip #198 https://www.perivision.net/wordpress/2011/03/how-to-make-excel-open-each-file-in-a-separate-window-tip-198/ https://www.perivision.net/wordpress/2011/03/how-to-make-excel-open-each-file-in-a-separate-window-tip-198/#comments Thu, 10 Mar 2011 19:23:16 +0000 http://www.perivision.net/wordpress/?p=4595 Read More]]> As a developer and analyst, I heavily rely on the powerful features and flexibility that Microsoft Excel provides for various tasks. This was especially true when I was supporting enterprise level accounting systems. I would often be working with two or more workbooks at a time, and loved having the ability to view two worksheets at the same time using dual monitors.

With the release of Excel 2007/2010, this ability to open two separate instances of Excel is no longer as easy as double-clicking on an Excel Shortcut anymore. Microsoft has forced users to one MDI container for all their Excel windows. As far as I can tell, the primary benefit of being constrained to one MDI container is less memory usage and features specific to DDE. Due to the nature of Excel and the numerous ways people use it, I think Microsoft was smart to make this the default behavior. However, their neglect in making this behavior optional, thereby forcing it on users, is unacceptable.

The popular way to get around this problem is to disable DDE in Excel, allowing you to once again open new windows in separate instances of Excel. Unfortunately, this breaks some essential DDE specific features, such as being able to copy formulas between separate instances of Excel.

Therefore, the best solution (for me) is to make opening a separate instance an option. Instead of double-left-clicking on the spreadsheet files, you will just use right-click and ‘Open in New Window’ whenever you wish to open a document in a completely new Excel instance.

To accomplish this, you will be creating a new Action like ‘Open in New Window’ on your popup action menu (right click), and this action can be set to ignore DDE. This will allow you independently control how Excel opens supported files (XLS, XLSX, CSV, etc).

The easiest way to do implement this is by following the instructions below:

Note: I have only verified that these instructions work on Windows XP and Office 2007/2010. If you try with different software, your results *may* vary.

1.      In Windows Explorer, go to Tools > Folder Options > File Types

2.      Scroll down to the XLS extension and click [Advanced]

3.      Click on “Open” in the list to highlight it and then click [Edit]

4.      Copy [CTRL-C] the Application Path contents to clipboard (or notepad)

  • Example: “C:\Program Files\Microsoft Office\Office14\EXCEL.EXE” /dde

5.      Click [Cancel] button to close the window

6.      Now, click [New] (to create a new Action)

7.      Give the action a name (like ‘Open in &New Window’)

8.      Paste [CTRL-V] the path from clipboard (or notepad)

9.      Now add the following to the end of the path you just pasted: <space>”%1″

  • Example: “C:\Program Files\Microsoft Office\Office14\EXCEL.EXE” /dde “%1”

10.    Verify that “Use DDE” is unchecked

11.    Click [OK] to save changes

12.    Rinse and Repeat (from step 2) for XLSX, XLSM and CSV extensions

DONE!

You should now be able to right-click on an excel file and click on ‘Open in New Window’ (or whatever name you entered for Step 7), and Excel will open that file in a completely new instance.

Finally, as Step 12 implies, if there are other extensions that Excel supports which you would like to open in a separate instance, just repeat steps 2 through 11 for each extension.

I hope you find this regained freedom as beneficial as I have!

Charles Peri is a programmer analyst with 20+ years of programming and database development experience.

Share and Enjoy !

Shares
]]>
https://www.perivision.net/wordpress/2011/03/how-to-make-excel-open-each-file-in-a-separate-window-tip-198/feed/ 12 4595