Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
kcdonaldson
 
Posts: n/a
Default Macro giving errors at workbook open

I have several macros built into this workbook. One of the macros is supposed
to clear all fields in several different ranges. I get the error "cannot
change part of a merged cell" and then when i removed any merged cells from
the ranges i get some kind of global error. i wiil post my macro here, can
anyone tell me what i'm doing wrong?

Workbook :

Option Explicit
'Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
' Call ChkData
' If CancelA = True Then Cancel = True
'End Sub
Private Sub Workbook_Open()
Dim RngName As Variant
For Each RngName In Array("ClearEOSV1", "ClearSEMErrorsV1",
"DEVLogOlivetteV1", "DEVLogOverlandV1", "ClearNMXNSGV1", "ClearNMXSIMV1")
Range(RngName).ClearContents
Next RngName
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
MsgBox "Double check everything before you save!"
Dim res As Long
res = MsgBox(prompt:="Did you check all of the SEMs?", _
Buttons:=vbYesNo)
Cancel = res = vbNo
res = MsgBox(prompt:="Did you check all of the NC1500s?", _
Buttons:=vbYesNo)
Cancel = res = vbNo
res = MsgBox(prompt:="Have you forgotten to validate your timestamps?", _
Buttons:=vbYesNo)
Cancel = res = vbYes
End Sub
__________________________________________________ __________________
Module 2:

Option Explicit
Public CancelA As Boolean
Sub ChkData()
Dim RngName As Variant
Dim Msg As String
Dim Designation As String
CancelA = False
For Each RngName In Array("EOSV1", "SEMErrorsV1", "DEVLogOlivetteV1",
"DEVLogOverlandV1", "NMXNSGV1", "NMXSIMULTRANSV1")
If RngName = "EOSV1" Or RngName = "SEMErrorsV1" Then
If Application.CountA(Range(RngName)) < Range(RngName).Count Then _
GoTo ErrorInData
Else
If Application.CountA(Range(RngName)) < 1 Then _
GoTo ErrorInData
End If
Next RngName
Exit Sub
ErrorInData:
CancelA = True
Select Case RngName
Case "EOSV1": Designation = "EOS"
Case "SEMErrorsV1": Designation = "SEM Errors"
Case "DEVLogOlivetteV1": Designation = "DEV Log for Olivette"
Case "DEVLogOverlandV1": Designation = "Dev Log for Overland"
Case "NMXNSGV1": Designation = "NMX for the NSG network"
Case "NMXSIMULTRANSV1": Designation = "NMX for the Simultrans network"
End Select
If RngName = "EOSV1" Or RngName = "SEMErrorsV1" Then
Msg = "You have not completely filled out the '" & Designation & "'
tab! You must complete the entire report before you save."
Else
Msg = "You have not noted any information about the '" & Designation
& "'. If there were no major alarms, please note so."
End If
MsgBox Msg, 16, "Data Error"
End Sub



  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Macro giving errors at workbook open

Instead of using:
Range(RngName).ClearContents
use:
Range(RngName).value = ""



kcdonaldson wrote:

I have several macros built into this workbook. One of the macros is supposed
to clear all fields in several different ranges. I get the error "cannot
change part of a merged cell" and then when i removed any merged cells from
the ranges i get some kind of global error. i wiil post my macro here, can
anyone tell me what i'm doing wrong?

Workbook :

Option Explicit
'Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
' Call ChkData
' If CancelA = True Then Cancel = True
'End Sub
Private Sub Workbook_Open()
Dim RngName As Variant
For Each RngName In Array("ClearEOSV1", "ClearSEMErrorsV1",
"DEVLogOlivetteV1", "DEVLogOverlandV1", "ClearNMXNSGV1", "ClearNMXSIMV1")
Range(RngName).ClearContents
Next RngName
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
MsgBox "Double check everything before you save!"
Dim res As Long
res = MsgBox(prompt:="Did you check all of the SEMs?", _
Buttons:=vbYesNo)
Cancel = res = vbNo
res = MsgBox(prompt:="Did you check all of the NC1500s?", _
Buttons:=vbYesNo)
Cancel = res = vbNo
res = MsgBox(prompt:="Have you forgotten to validate your timestamps?", _
Buttons:=vbYesNo)
Cancel = res = vbYes
End Sub
__________________________________________________ __________________
Module 2:

Option Explicit
Public CancelA As Boolean
Sub ChkData()
Dim RngName As Variant
Dim Msg As String
Dim Designation As String
CancelA = False
For Each RngName In Array("EOSV1", "SEMErrorsV1", "DEVLogOlivetteV1",
"DEVLogOverlandV1", "NMXNSGV1", "NMXSIMULTRANSV1")
If RngName = "EOSV1" Or RngName = "SEMErrorsV1" Then
If Application.CountA(Range(RngName)) < Range(RngName).Count Then _
GoTo ErrorInData
Else
If Application.CountA(Range(RngName)) < 1 Then _
GoTo ErrorInData
End If
Next RngName
Exit Sub
ErrorInData:
CancelA = True
Select Case RngName
Case "EOSV1": Designation = "EOS"
Case "SEMErrorsV1": Designation = "SEM Errors"
Case "DEVLogOlivetteV1": Designation = "DEV Log for Olivette"
Case "DEVLogOverlandV1": Designation = "Dev Log for Overland"
Case "NMXNSGV1": Designation = "NMX for the NSG network"
Case "NMXSIMULTRANSV1": Designation = "NMX for the Simultrans network"
End Select
If RngName = "EOSV1" Or RngName = "SEMErrorsV1" Then
Msg = "You have not completely filled out the '" & Designation & "'
tab! You must complete the entire report before you save."
Else
Msg = "You have not noted any information about the '" & Designation
& "'. If there were no major alarms, please note so."
End If
MsgBox Msg, 16, "Data Error"
End Sub


--

Dave Peterson
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
run macro on workbook close Nigel Excel Discussion (Misc queries) 3 November 29th 05 08:48 PM
Links only update when external workbook is open CMB Excel Worksheet Functions 6 November 8th 05 12:39 AM
Macro to open print window and set to print entire workbook retseort Excel Discussion (Misc queries) 1 October 27th 05 11:00 PM
Issuing macro in workbook from separate workbook Nigel Excel Discussion (Misc queries) 1 May 16th 05 05:46 PM
Excel 2003 hangs when trying to locate a workbook to open Darren Hill via OfficeKB.com Excel Discussion (Misc queries) 1 March 24th 05 12:41 PM


All times are GMT +1. The time now is 06:05 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"