Microsoft Excel for PC Logo
Posted on Aug 23, 2009
Answered by a Fixya Expert

Trustworthy Expert Solutions

At Fixya.com, our trusted experts are meticulously vetted and possess extensive experience in their respective fields. Backed by a community of knowledgeable professionals, our platform ensures that the solutions provided are thoroughly researched and validated.

View Our Top Experts

I copied the following: Private Sub Worksheet_Change(ByVal Target As Range) If Target.Cells.Count > 1 Then Exit Sub If Not Intersect(Target, Range(''A2:A100'')) Is Nothing Then With Target(1, 2) .Value = Now .EntireColumn.AutoFit End With End If End Sub into the view code in excel. It works fine for me time and date stamping when I make an entry in a cell. The problem is when I close the workbook and re open it to make another entry the time and date stamp is no longer there. I have to re copy the formula in the view code. How do I make my spreadsheet keep that formula so I can make an entry and a static date and time stamp is auto loaded in a corresponding cell.

1 Answer

David Shaub

Level 3:

An expert who has achieved level 3 by getting 1000 points

All-Star:

An expert that got 10 achievements.

MVP:

An expert that got 5 achievements.

President:

An expert whose answer got voted for 500 times.

  • Microsoft Master 2,994 Answers
  • Posted on Aug 23, 2009
David Shaub
Microsoft Master
Level 3:

An expert who has achieved level 3 by getting 1000 points

All-Star:

An expert that got 10 achievements.

MVP:

An expert that got 5 achievements.

President:

An expert whose answer got voted for 500 times.

Joined: Jan 01, 2009
Answers
2994
Questions
2
Helped
1152801
Points
8370

This will fix you up. You can just use the date stamp or the date and time stamp.

1 2 3 A B Formula Description (Result) =TODAY() Current date (varies) =NOW() Current date and time (varies)

Add Your Answer

×

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

0helpful
1answer

Earlier it was printing ok but now it is not printing.

Yes you would create an on change event that runs a print and delete and select commands.
In vba of sheet1 enter this code change in code a4 and sheets (1) as necessary I tested and works so if problem its put in wrong place.

If you change it note I didn't insert an error handling script so you may need escape or control + break to stop loop. For instance if you don't delete the value thats to be greater then 0 every delete will create an on change event and loop.


Private Sub Worksheet_Change(ByVal Target As Range)
If Range("a4") > 0 Then
Sheets(1).PrintOut
Range("a4").Delete
Range("a4").Select
End If
tip

How to datagridview to excel in C#

First, add this to your namespace.
using Microsoft.Office.Interop.Excel;

Then, copy the codes below and paste it into the export button click event.

Microsoft.Office.Interop.Excel.Application wapp;
Microsoft.Office.Interop.Excel.Worksheet wsheet;
Microsoft.Office.Interop.Excel.Workbook wbook;
wapp = new Microsoft.Office.Interop.Excel.Application();
wapp.Visible = false;
wbook = wapp.Workbooks.Add(true);
wsheet = (Worksheet)wbook.ActiveSheet;

if (dataGridView1.RowCount == 0)
{
mssgbox_noretrieve();
return;
}
try
{
for (int i = 0; i < this.dataGridView1.Columns.Count; i++)
{
wsheet.Cells[1, i + 1] = this.dataGridView1.Columns[i].HeaderText;
}

for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
{
DataGridViewRow row = this.dataGridView1.Rows[i];
for (int j = 0; j < row.Cells.Count; j++)
{
DataGridViewCell cell = row.Cells[j];
try
{
wsheet.Cells[i + 2, j + 1] = (cell.Value == null) ? "" : cell.Value.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
wapp.Visible = true;
}
catch (Exception ex1)
{
MessageBox.Show(ex1.Message);
}
wapp.UserControl = true;




That's all and enjoy...
Larrix



on Jul 09, 2011 • Computers & Internet
0helpful
2answers

I NEED MS EXCEL CONVERT FORMULA FOR NUMBER TO CURRENCY

Here is a very popular bit of code from Microsoft that will convert any currency amount in a cell to English words. All code and text from below here is the work of Microsoft.

Summary
This article shows you how to create a sample, user-defined function named ConvertCurrencyToEnglish() to convert a numeric value to an English word representation. For example, the function will return the following words for the number 1234.56: One Thousand Two Hundred Thirty Four Dollars And Fifty Six Cents

The Function Wizard can also be used to enter a custom function in a worksheet. To use the Function Wizard, follow these steps:

1. Click the Function Wizard button, and select User Defined under Function Category.
2. Select ConvertCurrencyToEnglish, and enter your number or cell reference.
3. Click Finish

To Create the Sample Functions

1. Insert a module sheet into a workbook. To do this in Microsoft Excel 97 or Microsoft Excel 98, point to Macro on the Tools menu, and then click Visual Basic Editor. In the Visual Basic Editor, click Module on the Insert menu. In Microsoft Excel 5.0 or 7.0, point to Macro on the Insert menu and click Module.

2. Type the following code into the module sheet.
Function ConvertCurrencyToEnglish (ByVal MyNumber)

Dim Temp

Dim Dollars, Cents

Dim DecimalPlace, Count



ReDim Place(9) As String

Place(2) = " Thousand "

Place(3) = " Million "

Place(4) = " Billion "

Place(5) = " Trillion "



' Convert MyNumber to a string, trimming extra spaces.

MyNumber = Trim(Str(MyNumber))



' Find decimal place.

DecimalPlace = InStr(MyNumber, ".")



' If we find decimal place...

If DecimalPlace > 0 Then

' Convert cents

Temp = Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)

Cents = ConvertTens(Temp)



' Strip off cents from remainder to convert.

MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))

End If



Count = 1

Do While MyNumber <> ""

' Convert last 3 digits of MyNumber to English dollars.

Temp = ConvertHundreds(Right(MyNumber, 3))

If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars

If Len(MyNumber) > 3 Then

' Remove last 3 converted digits from MyNumber.

MyNumber = Left(MyNumber, Len(MyNumber) - 3)

Else

MyNumber = ""

End If

Count = Count + 1

Loop



' Clean up dollars.

Select Case Dollars

Case ""

Dollars = "No Dollars"

Case "One"

Dollars = "One Dollar"

Case Else

Dollars = Dollars & " Dollars"

End Select



' Clean up cents.

Select Case Cents

Case ""

Cents = " And No Cents"

Case "One"

Cents = " And One Cent"

Case Else

Cents = " And " & Cents & " Cents"

End Select



ConvertCurrencyToEnglish = Dollars & Cents

End Function







Private Function ConvertHundreds (ByVal MyNumber)

Dim Result As String



' Exit if there is nothing to convert.

If Val(MyNumber) = 0 Then Exit Function



' Append leading zeros to number.

MyNumber = Right("000" & MyNumber, 3)



' Do we have a hundreds place digit to convert?

If Left(MyNumber, 1) <> "0" Then

Result = ConvertDigit(Left(MyNumber, 1)) & " Hundred "

End If



' Do we have a tens place digit to convert?

If Mid(MyNumber, 2, 1) <> "0" Then

Result = Result & ConvertTens(Mid(MyNumber, 2))

Else

' If not, then convert the ones place digit.

Result = Result & ConvertDigit(Mid(MyNumber, 3))

End If



ConvertHundreds = Trim(Result)

End Function







Private Function ConvertTens (ByVal MyTens)

Dim Result As String



' Is value between 10 and 19?

If Val(Left(MyTens, 1)) = 1 Then

Select Case Val(MyTens)

Case 10: Result = "Ten"

Case 11: Result = "Eleven"

Case 12: Result = "Twelve"

Case 13: Result = "Thirteen"

Case 14: Result = "Fourteen"

Case 15: Result = "Fifteen"

Case 16: Result = "Sixteen"

Case 17: Result = "Seventeen"

Case 18: Result = "Eighteen"

Case 19: Result = "Nineteen"

Case Else

End Select

Else

' .. otherwise it's between 20 and 99.

Select Case Val(Left(MyTens, 1))

Case 2: Result = "Twenty "

Case 3: Result = "Thirty "

Case 4: Result = "Forty "

Case 5: Result = "Fifty "

Case 6: Result = "Sixty "

Case 7: Result = "Seventy "

Case 8: Result = "Eighty "

Case 9: Result = "Ninety "

Case Else

End Select



' Convert ones place digit.

Result = Result & ConvertDigit(Right(MyTens, 1))

End If



ConvertTens = Result

End Function







Private Function ConvertDigit (ByVal MyDigit)

Select Case Val(MyDigit)

Case 1: ConvertDigit = "One"

Case 2: ConvertDigit = "Two"

Case 3: ConvertDigit = "Three"

Case 4: ConvertDigit = "Four"

Case 5: ConvertDigit = "Five"

Case 6: ConvertDigit = "Six"

Case 7: ConvertDigit = "Seven"

Case 8: ConvertDigit = "Eight"

Case 9: ConvertDigit = "Nine"

Case Else: ConvertDigit = ""

End Select

End Function
2helpful
1answer

Program code that can light a bulb using vb

You can do it a couple of ways, but this would probably be the shortest. Realize this depends on what forms you're qualifying for the pictures.

  1. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2. '
  3. PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
  4. End Sub
  5. Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  6. '
  7. PictureBox1.Image = Image.FromFile("C:\BulbOn.jpg")
  8. End Sub
  9. Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
  10. '
  11. PictureBox1.Image = Image.FromFile("C:\BulbOff.jpg")
  12. End Sub
1helpful
1answer

How to do Undo and Redo in Visaul Basic Project ? I wanna do in my application(Project). Suggest me Code for it .

Undo command: if you want an undo command, the best way to do it is to 'send' key strokes to the textbox that you want to use. You will need to send Ctrl+Z. You can do this with this code:
'=========================
'General Declarations
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const KEYEVENTF_KEYUP = &H2
Private Sub Command1_Click() 'The procedure that will run the undo command
Text1.SetFocus 'The textbox that you want to 'undo'
'Send Ctrl+Z
keybd_event 17, 0, 0, 0
keybd_event 90, 0, 0, 0
'Release Ctrl+Z
keybd_event 90, 0, KEYEVENTF_KEYUP, 0
keybd_event 17, 0, KEYEVENTF_KEYUP, 0
End Sub
'===================================

Another way to do this is to use the SendKeys statement. However, the API function gives you more control.
'===================================
Private Sub Command1_Click() 'The procedure that will run the undo command
Text1.SetFocus 'The textbox that you want to 'undo'
'Send Ctrl+Z
SendKeys "^Z"
End Sub
'====================================
0helpful
1answer

Using sumifs formula accross multiple sheets

Here is the syntax: =SUMIF(Sheet2!A1:A3,"> 1", Sheet2!B1:B3)

This says if the cells A1 through A3 in worksheet "Sheet2" are greater than 1 then return the values from worksheet "Sheet2" cells B1 through B3.

Change the worksheet name Sheet2 to your worksheet name and change the cell references to the ones you need.
0helpful
1answer

Out of memory error

1. Use with - End With for values

with xlWbk.Worksheets(1)
.Range(.cells(1), .cells(4)).value = "Some Repeated Text"
end with

2. Use following VB code for killing excle at the end:

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As Any, ByVal lpWindowName As Any) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As
Long

Private Const WM_QUIT = &H12

Sub TerminateExcel()

Dim lpClassName As String
Dim iHwnd As Long
Dim iReturn As Long

lpClassName = "XLMain"
iHwnd = FindWindow(lpClassName, 0&)

If iHwnd Then
iReturn = PostMessage(iHwnd, WM_QUIT, 0&, 0&)
End If

End Sub
0helpful
1answer

Macro code for copying a range of cells from one Excell w/sheet t

You did not respond to my claification request. Here is some code that might help, it copies a selection of cells going down until an emty cell is found and across until an emty cell is found. This is form an earlier version of office but should comeclose to woring in 2007.

Sub copyrange()
'
' copyrange Macro
' Macro written by Royal 11/22/2008.
'


'save the return values
wksname = ActiveSheet.Name
returncell = ActiveCell.Address
searchfor = ActiveCell.Value

'go to first worksheet and find entered value (note this is a value serach)
Worksheets(1).Activate
findfor = "A1"
On Error Resume Next

findfor = Cells.Find(What:=searchfor, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False).Address
If findfor = "A1" Then
erwks = ActiveSheet.Name
Sheets(wksname).Activate
er = MsgBox("Search item not found on Worksheet" + erwks, , "Search Error")
Exit Sub
Else
findfor.Activate
End If

Cells.FindNext(After:=ActiveCell).Activate

'save this address and start searching for copy area boundaries
begcell = ActiveCell.Address
begcl = ActiveCell.Cells.Column
begri = ActiveCell.Cells.Row
'search amaximum of 1000 rows and 676 columns
endri = begri + 1000
endcl = 26 * 26
maxrow = 0
maxcol = 0

For col = Cells.Column To endcl
If Cells(begri, col) = "" Then
maxcol = col
col = endcl
ri = endri
Else
ri = begri
End If
For ri = ri To (Cells.Row + 1000)
If Cells(ri, col) = "" Then
If ri > maxrow Then
maxrow = ri
End If
ri = endri
End If
Next ri
Next col

maxrow = maxrow - 1
maxcol = maxcol - 1

'copy the selected area
endcell = Cells(maxrow, maxcol).Address
crnge = begcell & ":" & endcell
Range(crnge).Select
Selection.Copy
'go back and paste it in
Sheets(wksname).Activate
Range(returncell).Select
' use this if yo want to paste formulas etc.
'ActiveSheet.Paste
' use this code if you want to paste values instead of formulas etc.
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range(returncell).Select

0helpful
2answers

Excel formula creation

= (a3) minus (b3) won't do it for you?
0helpful
1answer

Exel 2003

You can refer to cells that are on other worksheets by perpending the name of the worksheet followed by an exclamation point (!) to the cell reference. In the following example, the AVERAGE worksheet function calculates the average value for the range C1:C10 on the worksheet named Marketing in the same workbook.

default.aspx?assetid=za010939481033 Refers to the worksheet named Marketing default.aspx?assetid=za010939491033 Refers to the range of cells between C1 and C10, inclusively
  1. Click the cell in which you want to enter the formula.
  2. In the formula bar (formula bar: A bar at the top of the Excel window that you use to enter or edit values or formulas in cells or charts. Displays the constant value or formula stored in the active cell.) default.aspx?assetid=za060515351033, type = (equal sign).
  3. Click the tab for the worksheet to be referenced.
  4. Select the cell or range of cells to be referenced.
Not finding what you are looking for?

274 views

Ask a Question

Usually answered in minutes!

Top Microsoft Computers & Internet Experts

Grand Canyon Tech
Grand Canyon Tech

Level 3 Expert

3867 Answers

k24674

Level 3 Expert

8093 Answers

Brad Brown

Level 3 Expert

19187 Answers

Are you a Microsoft Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...