Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default VBA Code wanted for Excel

VBA code needed to: enter choice of 1 or 2 in column 33 with 1 being equal
to 1495 and 2 equal to 3995, at the same time enter 1 in column 31 and the
Date in column 32
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default VBA Code wanted for Excel

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 33 Then
Application.EnableEvents = False
With Target
If .Value = 1 Then
.Value = 1495
ElseIf .Value = 2 Then
.Value = 3995
End If
End With
With Target
.Offset(0, -2).Value = 1
.Offset(0, -1).Value = Format(Date, "mm/dd/yyyy")
End With
End If
Application.EnableEvents = True
End Sub

This is sheet event code. Right-click on the sheet tab and "View Code".

Copy/paste into that sheet module. Alt + q to return to the Excel window.

Type a 1 or two in any cell of column 33(AG)


Gord Dibben MS Excel MVP

On Mon, 3 Mar 2008 14:50:06 -0800, lost in Chicago
wrote:

VBA code needed to: enter choice of 1 or 2 in column 33 with 1 being equal
to 1495 and 2 equal to 3995, at the same time enter 1 in column 31 and the
Date in column 32


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default VBA Code wanted for Excel

hmmmmmm nothing happened I've got excel 2003 tried it twice with no results???

"Gord Dibben" wrote:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 33 Then
Application.EnableEvents = False
With Target
If .Value = 1 Then
.Value = 1495
ElseIf .Value = 2 Then
.Value = 3995
End If
End With
With Target
.Offset(0, -2).Value = 1
.Offset(0, -1).Value = Format(Date, "mm/dd/yyyy")
End With
End If
Application.EnableEvents = True
End Sub

This is sheet event code. Right-click on the sheet tab and "View Code".

Copy/paste into that sheet module. Alt + q to return to the Excel window.

Type a 1 or two in any cell of column 33(AG)


Gord Dibben MS Excel MVP

On Mon, 3 Mar 2008 14:50:06 -0800, lost in Chicago
wrote:

VBA code needed to: enter choice of 1 or 2 in column 33 with 1 being equal
to 1495 and 2 equal to 3995, at the same time enter 1 in column 31 and the
Date in column 32



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default VBA Code wanted for Excel

hmmmmmmmmmmmm that's strange.

What do you mean you "tried it twice"?

Did you copy it into the worksheet module?

Did you enter a 1 or 2 in AG1?

Tested with your requirements as I interpreted them before posting.

I will re-post with an error trap added. I meant to put it in first time.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 33 Then
On Error GoTo endit
Application.EnableEvents = False
With Target
If .Value = 1 Then
.Value = 1495
ElseIf .Value = 2 Then
.Value = 3995
End If
End With
With Target
.Offset(0, -2).Value = 1
.Offset(0, -1).Value = Format(Date, "mm/dd/yyyy")
End With
End If
endit:
Application.EnableEvents = True
End Sub

I can post a workbook to a file host for you to download if you can't get this
working.


Gord


On Mon, 3 Mar 2008 16:43:26 -0800, lost in Chicago
wrote:

hmmmmmm nothing happened I've got excel 2003 tried it twice with no results???

"Gord Dibben" wrote:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 33 Then
Application.EnableEvents = False
With Target
If .Value = 1 Then
.Value = 1495
ElseIf .Value = 2 Then
.Value = 3995
End If
End With
With Target
.Offset(0, -2).Value = 1
.Offset(0, -1).Value = Format(Date, "mm/dd/yyyy")
End With
End If
Application.EnableEvents = True
End Sub

This is sheet event code. Right-click on the sheet tab and "View Code".

Copy/paste into that sheet module. Alt + q to return to the Excel window.

Type a 1 or two in any cell of column 33(AG)


Gord Dibben MS Excel MVP

On Mon, 3 Mar 2008 14:50:06 -0800, lost in Chicago
wrote:

VBA code needed to: enter choice of 1 or 2 in column 33 with 1 being equal
to 1495 and 2 equal to 3995, at the same time enter 1 in column 31 and the
Date in column 32




  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default VBA Code wanted for Excel

Ah working now. I changed: Private Sub Worksheet_Change(ByVal Target As... to
Private Sub Worksheet_Changeit(ByVal Target As... because I ALREADY HAD a
code with that name that game me an ambiguous error. I switched the names and
now it works Great! You are the MAN!! Thanks very much.

"Gord Dibben" wrote:

hmmmmmmmmmmmm that's strange.

What do you mean you "tried it twice"?

Did you copy it into the worksheet module?

Did you enter a 1 or 2 in AG1?

Tested with your requirements as I interpreted them before posting.

I will re-post with an error trap added. I meant to put it in first time.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 33 Then
On Error GoTo endit
Application.EnableEvents = False
With Target
If .Value = 1 Then
.Value = 1495
ElseIf .Value = 2 Then
.Value = 3995
End If
End With
With Target
.Offset(0, -2).Value = 1
.Offset(0, -1).Value = Format(Date, "mm/dd/yyyy")
End With
End If
endit:
Application.EnableEvents = True
End Sub

I can post a workbook to a file host for you to download if you can't get this
working.


Gord


On Mon, 3 Mar 2008 16:43:26 -0800, lost in Chicago
wrote:

hmmmmmm nothing happened I've got excel 2003 tried it twice with no results???

"Gord Dibben" wrote:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 33 Then
Application.EnableEvents = False
With Target
If .Value = 1 Then
.Value = 1495
ElseIf .Value = 2 Then
.Value = 3995
End If
End With
With Target
.Offset(0, -2).Value = 1
.Offset(0, -1).Value = Format(Date, "mm/dd/yyyy")
End With
End If
Application.EnableEvents = True
End Sub

This is sheet event code. Right-click on the sheet tab and "View Code".

Copy/paste into that sheet module. Alt + q to return to the Excel window.

Type a 1 or two in any cell of column 33(AG)


Gord Dibben MS Excel MVP

On Mon, 3 Mar 2008 14:50:06 -0800, lost in Chicago
wrote:

VBA code needed to: enter choice of 1 or 2 in column 33 with 1 being equal
to 1495 and 2 equal to 3995, at the same time enter 1 in column 31 and the
Date in column 32






  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default VBA Code wanted for Excel

Good to hear, but now you have only one set of event code that works.

Private Sub Worksheet_Changeit(ByVal Target As Range) is not a legal event so
Excel will just ignore it.


Gord

On Mon, 3 Mar 2008 17:39:01 -0800, lost in Chicago
wrote:

Ah working now. I changed: Private Sub Worksheet_Change(ByVal Target As... to
Private Sub Worksheet_Changeit(ByVal Target As... because I ALREADY HAD a
code with that name that game me an ambiguous error. I switched the names and
now it works Great! You are the MAN!! Thanks very much.

"Gord Dibben" wrote:

hmmmmmmmmmmmm that's strange.

What do you mean you "tried it twice"?

Did you copy it into the worksheet module?

Did you enter a 1 or 2 in AG1?

Tested with your requirements as I interpreted them before posting.

I will re-post with an error trap added. I meant to put it in first time.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 33 Then
On Error GoTo endit
Application.EnableEvents = False
With Target
If .Value = 1 Then
.Value = 1495
ElseIf .Value = 2 Then
.Value = 3995
End If
End With
With Target
.Offset(0, -2).Value = 1
.Offset(0, -1).Value = Format(Date, "mm/dd/yyyy")
End With
End If
endit:
Application.EnableEvents = True
End Sub

I can post a workbook to a file host for you to download if you can't get this
working.


Gord


On Mon, 3 Mar 2008 16:43:26 -0800, lost in Chicago
wrote:

hmmmmmm nothing happened I've got excel 2003 tried it twice with no results???

"Gord Dibben" wrote:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 33 Then
Application.EnableEvents = False
With Target
If .Value = 1 Then
.Value = 1495
ElseIf .Value = 2 Then
.Value = 3995
End If
End With
With Target
.Offset(0, -2).Value = 1
.Offset(0, -1).Value = Format(Date, "mm/dd/yyyy")
End With
End If
Application.EnableEvents = True
End Sub

This is sheet event code. Right-click on the sheet tab and "View Code".

Copy/paste into that sheet module. Alt + q to return to the Excel window.

Type a 1 or two in any cell of column 33(AG)


Gord Dibben MS Excel MVP

On Mon, 3 Mar 2008 14:50:06 -0800, lost in Chicago
wrote:

VBA code needed to: enter choice of 1 or 2 in column 33 with 1 being equal
to 1495 and 2 equal to 3995, at the same time enter 1 in column 31 and the
Date in column 32





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
Excel shutting down - not wanted! Linda Broyles Excel Discussion (Misc queries) 5 August 8th 08 05:07 PM
Excel formula help wanted sharpe-e Excel Discussion (Misc queries) 3 February 27th 08 01:48 AM
Wanted: Business Excel Books General Fear Excel Discussion (Misc queries) 1 August 3rd 06 02:36 PM
Wanted: Busines Excel Books General Fear Excel Discussion (Misc queries) 0 August 3rd 06 02:19 PM
Excel 2007: More control over graphs wanted Thomas D Excel Discussion (Misc queries) 1 July 2nd 06 05:45 PM


All times are GMT +1. The time now is 07:25 PM.

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"