Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Owl Owl is offline
external usenet poster
 
Posts: 14
Default Err number 6 in my first macro written! Drop down box not working

Hi,

Ive set up a macro where i can pick a promotion from a drop down list and it
pulls out all of the products which ran that promotion from another sheet.
Ive set all my variables up as integers so this could be the issue.

I want to be able to put other drop down menus in so i can cut the data in
any which way.....so i wanted to make sure this code was perfect....

This is my code - hopefully not too much info for anyone out there but
thought it might help more than me trying to explain...

Option Explicit
Option Compare Text


Public Promotion As String

Dim NoRows As Integer 'Number of rows with data in "Total Sales"
Dim Counter As Integer 'Keeps count of rows checked
Dim SalesRow As Integer 'Indicates which row is being copied
Dim NewSalesRow As Integer 'Indicates which row in new sheet is the data
going
Dim Uplift As Integer 'Calculates the Uplift for each transaction
Dim TotalUplift As Integer 'Holds the total Uplift for each Promotion
Sub salesmain()

On Error GoTo Errorhandler

'Err.Raise 11

Application.ScreenUpdating = False

Call CreateSheet
Call CopyHeadings
Call CopySalesRecords

Call formatcolumns

Exit Sub

Errorhandler:

If Err.Number = 6 Then

MsgBox "You entered the wrongname" & vbCrLf & _
"The system is reseting" & vbCrLf & "Make sure you enter a correct
name" _

Application.DisplayAlerts = False
Sheets(Promotion).Delete
Application.DisplayAlerts = True

Else

MsgBox "Unexpected error. type :" & Err.Number & vbCrLf & vbCrLf & _
Err.Description & vbCrLf & vbCrLf & "Contact the helpdesk"

End If


End Sub

Sub CreateSheet()
'
' CreateSheet Macro
'

Call DeleteSheetIfExists
Sheets.Add After:=Sheets(Sheets.Count)
'adds the sheet after the last count

ActiveSheet.Name = Promotion

End Sub

Sub DeleteSheetIfExists()

Dim SheetVar As Worksheet
For Each SheetVar In ActiveWorkbook.Worksheets

'Debug.Print SheetVar.Name

If SheetVar.Name = Promotion Then
Application.DisplayAlerts = False
SheetVar.Delete
Application.DisplayAlerts = True

Exit For

End If

Next SheetVar

End Sub
Sub CopyHeadings()
'
' CopyHeadings Macro
'

'
Sheets("Marketing Summary").Range("A1:Q1").Copy
Sheets(Promotion).Select
Range("A1").Select
ActiveSheet.Paste


Range("A10").Select
Application.CutCopyMode = False

End Sub

Sub formatcolumns()

Sheets(Promotion).Select

Columns("A:Q").EntireColumn.AutoFit

Range("A1").Select

End Sub

Sub CopySalesRecords()

SalesRow = 2
NewSalesRow = 2

Sheets("Marketing Summary").Select
Range("A2").Select

NoRows = ActiveCell.CurrentRegion.Rows.Count

For Counter = 1 To NoRows

If Cells(SalesRow, 2) = Promotion Then

Range(Cells(SalesRow, 1), Cells(SalesRow, 17)).Copy

Sheets(Promotion).Select
Cells(NewSalesRow, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

Call calcTotals

NewSalesRow = NewSalesRow + 1

Sheets("Marketing Summary").Select

End If

SalesRow = SalesRow + 1

Next Counter

Call AddTotals

End Sub

Sub calcTotals()


'Cells(NewSalesRow, 13) = Uplift

TotalUplift = TotalUplift + Cells(NewSalesRow, 13)
End Sub

Sub AddTotals()

Sheets(Promotion).Select

NewSalesRow = NewSalesRow + 1

Cells(NewSalesRow, 12) = "Totals"
Cells(NewSalesRow, 13) = TotalUplift

Rows(NewSalesRow).Font.Bold = True


End Sub



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Err number 6 in my first macro written! Drop down box not working

For testing purposes comment out the On Error statement so you can find where
the error is occuring.

"Owl" wrote:

Hi,

Ive set up a macro where i can pick a promotion from a drop down list and it
pulls out all of the products which ran that promotion from another sheet.
Ive set all my variables up as integers so this could be the issue.

I want to be able to put other drop down menus in so i can cut the data in
any which way.....so i wanted to make sure this code was perfect....

This is my code - hopefully not too much info for anyone out there but
thought it might help more than me trying to explain...

Option Explicit
Option Compare Text


Public Promotion As String

Dim NoRows As Integer 'Number of rows with data in "Total Sales"
Dim Counter As Integer 'Keeps count of rows checked
Dim SalesRow As Integer 'Indicates which row is being copied
Dim NewSalesRow As Integer 'Indicates which row in new sheet is the data
going
Dim Uplift As Integer 'Calculates the Uplift for each transaction
Dim TotalUplift As Integer 'Holds the total Uplift for each Promotion
Sub salesmain()

On Error GoTo Errorhandler

'Err.Raise 11

Application.ScreenUpdating = False

Call CreateSheet
Call CopyHeadings
Call CopySalesRecords

Call formatcolumns

Exit Sub

Errorhandler:

If Err.Number = 6 Then

MsgBox "You entered the wrongname" & vbCrLf & _
"The system is reseting" & vbCrLf & "Make sure you enter a correct
name" _

Application.DisplayAlerts = False
Sheets(Promotion).Delete
Application.DisplayAlerts = True

Else

MsgBox "Unexpected error. type :" & Err.Number & vbCrLf & vbCrLf & _
Err.Description & vbCrLf & vbCrLf & "Contact the helpdesk"

End If


End Sub

Sub CreateSheet()
'
' CreateSheet Macro
'

Call DeleteSheetIfExists
Sheets.Add After:=Sheets(Sheets.Count)
'adds the sheet after the last count

ActiveSheet.Name = Promotion

End Sub

Sub DeleteSheetIfExists()

Dim SheetVar As Worksheet
For Each SheetVar In ActiveWorkbook.Worksheets

'Debug.Print SheetVar.Name

If SheetVar.Name = Promotion Then
Application.DisplayAlerts = False
SheetVar.Delete
Application.DisplayAlerts = True

Exit For

End If

Next SheetVar

End Sub
Sub CopyHeadings()
'
' CopyHeadings Macro
'

'
Sheets("Marketing Summary").Range("A1:Q1").Copy
Sheets(Promotion).Select
Range("A1").Select
ActiveSheet.Paste


Range("A10").Select
Application.CutCopyMode = False

End Sub

Sub formatcolumns()

Sheets(Promotion).Select

Columns("A:Q").EntireColumn.AutoFit

Range("A1").Select

End Sub

Sub CopySalesRecords()

SalesRow = 2
NewSalesRow = 2

Sheets("Marketing Summary").Select
Range("A2").Select

NoRows = ActiveCell.CurrentRegion.Rows.Count

For Counter = 1 To NoRows

If Cells(SalesRow, 2) = Promotion Then

Range(Cells(SalesRow, 1), Cells(SalesRow, 17)).Copy

Sheets(Promotion).Select
Cells(NewSalesRow, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

Call calcTotals

NewSalesRow = NewSalesRow + 1

Sheets("Marketing Summary").Select

End If

SalesRow = SalesRow + 1

Next Counter

Call AddTotals

End Sub

Sub calcTotals()


'Cells(NewSalesRow, 13) = Uplift

TotalUplift = TotalUplift + Cells(NewSalesRow, 13)
End Sub

Sub AddTotals()

Sheets(Promotion).Select

NewSalesRow = NewSalesRow + 1

Cells(NewSalesRow, 12) = "Totals"
Cells(NewSalesRow, 13) = TotalUplift

Rows(NewSalesRow).Font.Bold = True


End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
Owl Owl is offline
external usenet poster
 
Posts: 14
Default Err number 6 in my first macro written! Drop down box not wor

Hi Joel,

Just did that and it seems to stall at 'Sheets(Promotion).Select' - do you
know why that might be? It seems to work with some promotions and then with
others i get an error....



Sub CopyHeadings()
'
' CopyHeadings Macro
'

'
Sheets("Marketing Summary").Range("A1:Q1").Copy
Sheets(Promotion).Select
Range("A1").Select



"joel" wrote:

For testing purposes comment out the On Error statement so you can find where
the error is occuring.

"Owl" wrote:

Hi,

Ive set up a macro where i can pick a promotion from a drop down list and it
pulls out all of the products which ran that promotion from another sheet.
Ive set all my variables up as integers so this could be the issue.

I want to be able to put other drop down menus in so i can cut the data in
any which way.....so i wanted to make sure this code was perfect....

This is my code - hopefully not too much info for anyone out there but
thought it might help more than me trying to explain...

Option Explicit
Option Compare Text


Public Promotion As String

Dim NoRows As Integer 'Number of rows with data in "Total Sales"
Dim Counter As Integer 'Keeps count of rows checked
Dim SalesRow As Integer 'Indicates which row is being copied
Dim NewSalesRow As Integer 'Indicates which row in new sheet is the data
going
Dim Uplift As Integer 'Calculates the Uplift for each transaction
Dim TotalUplift As Integer 'Holds the total Uplift for each Promotion
Sub salesmain()

On Error GoTo Errorhandler

'Err.Raise 11

Application.ScreenUpdating = False

Call CreateSheet
Call CopyHeadings
Call CopySalesRecords

Call formatcolumns

Exit Sub

Errorhandler:

If Err.Number = 6 Then

MsgBox "You entered the wrongname" & vbCrLf & _
"The system is reseting" & vbCrLf & "Make sure you enter a correct
name" _

Application.DisplayAlerts = False
Sheets(Promotion).Delete
Application.DisplayAlerts = True

Else

MsgBox "Unexpected error. type :" & Err.Number & vbCrLf & vbCrLf & _
Err.Description & vbCrLf & vbCrLf & "Contact the helpdesk"

End If


End Sub

Sub CreateSheet()
'
' CreateSheet Macro
'

Call DeleteSheetIfExists
Sheets.Add After:=Sheets(Sheets.Count)
'adds the sheet after the last count

ActiveSheet.Name = Promotion

End Sub

Sub DeleteSheetIfExists()

Dim SheetVar As Worksheet
For Each SheetVar In ActiveWorkbook.Worksheets

'Debug.Print SheetVar.Name

If SheetVar.Name = Promotion Then
Application.DisplayAlerts = False
SheetVar.Delete
Application.DisplayAlerts = True

Exit For

End If

Next SheetVar

End Sub
Sub CopyHeadings()
'
' CopyHeadings Macro
'

'
Sheets("Marketing Summary").Range("A1:Q1").Copy
Sheets(Promotion).Select
Range("A1").Select
ActiveSheet.Paste


Range("A10").Select
Application.CutCopyMode = False

End Sub

Sub formatcolumns()

Sheets(Promotion).Select

Columns("A:Q").EntireColumn.AutoFit

Range("A1").Select

End Sub

Sub CopySalesRecords()

SalesRow = 2
NewSalesRow = 2

Sheets("Marketing Summary").Select
Range("A2").Select

NoRows = ActiveCell.CurrentRegion.Rows.Count

For Counter = 1 To NoRows

If Cells(SalesRow, 2) = Promotion Then

Range(Cells(SalesRow, 1), Cells(SalesRow, 17)).Copy

Sheets(Promotion).Select
Cells(NewSalesRow, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

Call calcTotals

NewSalesRow = NewSalesRow + 1

Sheets("Marketing Summary").Select

End If

SalesRow = SalesRow + 1

Next Counter

Call AddTotals

End Sub

Sub calcTotals()


'Cells(NewSalesRow, 13) = Uplift

TotalUplift = TotalUplift + Cells(NewSalesRow, 13)
End Sub

Sub AddTotals()

Sheets(Promotion).Select

NewSalesRow = NewSalesRow + 1

Cells(NewSalesRow, 12) = "Totals"
Cells(NewSalesRow, 13) = TotalUplift

Rows(NewSalesRow).Font.Bold = True


End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Err number 6 in my first macro written! Drop down box not wor

It is not finding the promotion sheet. Myabe there is a space in the tab
name for the worksheet.

It is alway best to debug your code initially without the On Error
statments, then add the error testing later. Other method is to step through
code to find errors.

"Owl" wrote:

Hi Joel,

Just did that and it seems to stall at 'Sheets(Promotion).Select' - do you
know why that might be? It seems to work with some promotions and then with
others i get an error....



Sub CopyHeadings()
'
' CopyHeadings Macro
'

'
Sheets("Marketing Summary").Range("A1:Q1").Copy
Sheets(Promotion).Select
Range("A1").Select



"joel" wrote:

For testing purposes comment out the On Error statement so you can find where
the error is occuring.

"Owl" wrote:

Hi,

Ive set up a macro where i can pick a promotion from a drop down list and it
pulls out all of the products which ran that promotion from another sheet.
Ive set all my variables up as integers so this could be the issue.

I want to be able to put other drop down menus in so i can cut the data in
any which way.....so i wanted to make sure this code was perfect....

This is my code - hopefully not too much info for anyone out there but
thought it might help more than me trying to explain...

Option Explicit
Option Compare Text


Public Promotion As String

Dim NoRows As Integer 'Number of rows with data in "Total Sales"
Dim Counter As Integer 'Keeps count of rows checked
Dim SalesRow As Integer 'Indicates which row is being copied
Dim NewSalesRow As Integer 'Indicates which row in new sheet is the data
going
Dim Uplift As Integer 'Calculates the Uplift for each transaction
Dim TotalUplift As Integer 'Holds the total Uplift for each Promotion
Sub salesmain()

On Error GoTo Errorhandler

'Err.Raise 11

Application.ScreenUpdating = False

Call CreateSheet
Call CopyHeadings
Call CopySalesRecords

Call formatcolumns

Exit Sub

Errorhandler:

If Err.Number = 6 Then

MsgBox "You entered the wrongname" & vbCrLf & _
"The system is reseting" & vbCrLf & "Make sure you enter a correct
name" _

Application.DisplayAlerts = False
Sheets(Promotion).Delete
Application.DisplayAlerts = True

Else

MsgBox "Unexpected error. type :" & Err.Number & vbCrLf & vbCrLf & _
Err.Description & vbCrLf & vbCrLf & "Contact the helpdesk"

End If


End Sub

Sub CreateSheet()
'
' CreateSheet Macro
'

Call DeleteSheetIfExists
Sheets.Add After:=Sheets(Sheets.Count)
'adds the sheet after the last count

ActiveSheet.Name = Promotion

End Sub

Sub DeleteSheetIfExists()

Dim SheetVar As Worksheet
For Each SheetVar In ActiveWorkbook.Worksheets

'Debug.Print SheetVar.Name

If SheetVar.Name = Promotion Then
Application.DisplayAlerts = False
SheetVar.Delete
Application.DisplayAlerts = True

Exit For

End If

Next SheetVar

End Sub
Sub CopyHeadings()
'
' CopyHeadings Macro
'

'
Sheets("Marketing Summary").Range("A1:Q1").Copy
Sheets(Promotion).Select
Range("A1").Select
ActiveSheet.Paste


Range("A10").Select
Application.CutCopyMode = False

End Sub

Sub formatcolumns()

Sheets(Promotion).Select

Columns("A:Q").EntireColumn.AutoFit

Range("A1").Select

End Sub

Sub CopySalesRecords()

SalesRow = 2
NewSalesRow = 2

Sheets("Marketing Summary").Select
Range("A2").Select

NoRows = ActiveCell.CurrentRegion.Rows.Count

For Counter = 1 To NoRows

If Cells(SalesRow, 2) = Promotion Then

Range(Cells(SalesRow, 1), Cells(SalesRow, 17)).Copy

Sheets(Promotion).Select
Cells(NewSalesRow, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

Call calcTotals

NewSalesRow = NewSalesRow + 1

Sheets("Marketing Summary").Select

End If

SalesRow = SalesRow + 1

Next Counter

Call AddTotals

End Sub

Sub calcTotals()


'Cells(NewSalesRow, 13) = Uplift

TotalUplift = TotalUplift + Cells(NewSalesRow, 13)
End Sub

Sub AddTotals()

Sheets(Promotion).Select

NewSalesRow = NewSalesRow + 1

Cells(NewSalesRow, 12) = "Totals"
Cells(NewSalesRow, 13) = TotalUplift

Rows(NewSalesRow).Font.Bold = True


End Sub



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Err number 6 in my first macro written! Drop down box not wor

I don't see where the string variable 'Promotion' is defined...

i.e.

Promotion = "Promotion_Sheet"

Is it defined somewhere else?

Eric


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
Written number amounts ajchapaiii Excel Discussion (Misc queries) 4 September 16th 09 08:13 PM
Macros written in UK not working in US Teresa Excel Discussion (Misc queries) 1 April 19th 07 06:59 PM
How do I change a number to a written number? mHaro Excel Programming 2 August 23rd 06 10:18 PM
Problem with VBA code written in Excel 2002 working in Office 2003 [email protected] Excel Programming 2 July 11th 06 08:44 PM
macro written in Excel 2000 not working in Excel 2002 Ivan H. Excel Programming 0 August 21st 03 11:33 PM


All times are GMT +1. The time now is 10:09 AM.

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"