Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 14th, 2011, 06:18 AM
mounika mounika is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Posts: 2 mounika User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 2 sec
Reputation Power: 0
COPY/Paste of decimal values in sheet

hi ,
i am facing one problem while writing new code to the already exising vba code in my office,please help me...
in one sheet called resource worksheet for one column only it has to allow whole numbers,so already data validation was written for that column in the sheet,but while copy/paste of decimal or negative other than whole it is allowing...so i wrote code for that particular sheet which has already some code in it as follows,my code is in double quotes

it is giving error as "Method 'Range' of object '_Global' failed" ,while debugging i found that it is going to the logerror function after giving msg written in the code and not clearing the c.value,as it is going to the other page ,i will also give that page after the below block

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Worksheet_Change_err
" For Each c In Target
If (c.Value Like "*.*" Or c.Value Like "*-*") And c.Column = 3 Then
If boolinvalid = False Then
boolinvalid = True
MsgBox "The number can only be a whole number between 0 and 100,000,000,000,000,000", vbCritical
End If
c.Value = ""
ElseIf (Not IsNumeric(c.Value)) And c.Column = 3 Then
c.Value = ""
End If
Next"
5 Dim cell As Range
10 For Each cell In Target
15 If typeName(Target.Value) = "String" Then 'added to exclude the "add resource" function
20 If Target.row >= FIRST_ROW And Not Intersect(getResourceHeadingCell("Resource Name").EntireColumn, Target) Is Nothing And Not Trim(Target.Value) = "" Then
22 If isCollectByRegionOrOu Then
25 Application.EnableEvents = False
26 setDefaultCountry (Target.row)
27 'setDefaultOU (Target.row)
35 Application.EnableEvents = True
37 End If
40 End If
45 End If
50 Next cell
Exit Sub
Worksheet_Change_err:
logError "Worksheet_Change resource sheet", Erl, Err.description, Err.number
End Sub

------------------after c.value it is coming to this and not clearing the value ,this is my problem can you please help me on this ,please....

Public Sub logError(Optional subOrFuncName As String, Optional lineNum As Integer, Optional description As String, Optional number As Integer)
'logs errors to the errorLog worksheet
On Error Resume Next
Dim logRng As Range
checkForLog
Set logRng = Worksheets("ErrorLog").Range("A2")
logRng.EntireRow.Insert
logRng.Cells(0, 1).Value = Now
logRng.Cells(0, 2).Value = subOrFuncName
logRng.Cells(0, 3).Value = lineNum
logRng.Cells(0, 4).Value = description
logRng.Cells(0, 5).Value = number
Worksheets("ErrorLog").Rows(200).Delete
End Sub
Private Sub checkForLog()
'checks for the existance of the errorLog worksheet and creates it if needed
Dim errorLog As Worksheet
On Error GoTo noSheet
Set errorLog = Worksheets("ErrorLog")
Exit Sub
noSheet:
On Error Resume Next
Application.ScreenUpdating = False
Worksheets.Add(After:=Worksheets(Worksheets.count)).name = "ErrorLog"
With Range("ErrorLog!A1")
.Value = "Error Date / Time"
.EntireColumn.ColumnWidth = 15
.EntireColumn.HorizontalAlignment = xlLeft
.Cells(1, 2).Value = "Sub or Function Name"
.Cells(1, 2).EntireColumn.AutoFit
.Cells(1, 2).EntireColumn.ColumnWidth = 25
.Cells(1, 2).EntireColumn.HorizontalAlignment = xlLeft
.Cells(1, 3).Value = "Line Number"
.Cells(1, 3).EntireColumn.AutoFit
.Cells(1, 3).EntireColumn.ColumnWidth = 15
.Cells(1, 3).EntireColumn.HorizontalAlignment = xlLeft
.Cells(1, 4).Value = "Description"
.Cells(1, 4).EntireColumn.AutoFit
.Cells(1, 4).EntireColumn.ColumnWidth = 25
.Cells(1, 4).EntireColumn.HorizontalAlignment = xlLeft
.Cells(1, 5).Value = "Error Code"
.Cells(1, 5).EntireColumn.AutoFit
.Cells(1, 5).EntireColumn.ColumnWidth = 15
.Cells(1, 5).EntireColumn.HorizontalAlignment = xlLeft
End With
Worksheets("ErrorLog").Visible = xlSheetVeryHidden
Application.ScreenUpdating = True
End Sub
Public Sub showErrorLog()
On Error GoTo noLog
Worksheets("ErrorLog").Visible = xlSheetVisible
Worksheets("ErrorLog").Select
Exit Sub

noLog:
MsgBox "There are no errors to display"
End Sub

Reply With Quote
  #2  
Old December 23rd, 2011, 06:30 AM
Incidentals Incidentals is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2010
Posts: 89 Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level)Incidentals User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Day 4 h 23 m 19 sec
Reputation Power: 156
Quote:
Originally Posted by mounika
hi ,
i am facing one problem while writing new code to the already exising vba code in my office,please help me...
in one sheet called resource worksheet for one column only it has to allow whole numbers,so already data validation was written for that column in the sheet,but while copy/paste of decimal or negative other than whole it is allowing...so i wrote code for that particular sheet which has already some code in it as follows,my code is in double quotes

it is giving error as "Method 'Range' of object '_Global' failed" ,while debugging i found that it is going to the logerror function after giving msg written in the code and not clearing the c.value,as it is going to the other page ,i will also give that page after the below block

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Worksheet_Change_err
" For Each c In Target
If (c.Value Like "*.*" Or c.Value Like "*-*") And c.Column = 3 Then
If boolinvalid = False Then
boolinvalid = True
MsgBox "The number can only be a whole number between 0 and 100,000,000,000,000,000", vbCritical
End If
c.Value = ""
ElseIf (Not IsNumeric(c.Value)) And c.Column = 3 Then
c.Value = ""
End If
Next"
5 Dim cell As Range
10 For Each cell In Target
15 If typeName(Target.Value) = "String" Then 'added to exclude the "add resource" function
20 If Target.row >= FIRST_ROW And Not Intersect(getResourceHeadingCell("Resource Name").EntireColumn, Target) Is Nothing And Not Trim(Target.Value) = "" Then
22 If isCollectByRegionOrOu Then
25 Application.EnableEvents = False
26 setDefaultCountry (Target.row)
27 'setDefaultOU (Target.row)
35 Application.EnableEvents = True
37 End If
40 End If
45 End If
50 Next cell
Exit Sub
Worksheet_Change_err:
logError "Worksheet_Change resource sheet", Erl, Err.description, Err.number
End Sub

------------------after c.value it is coming to this and not clearing the value ,this is my problem can you please help me on this ,please....

Public Sub logError(Optional subOrFuncName As String, Optional lineNum As Integer, Optional description As String, Optional number As Integer)
'logs errors to the errorLog worksheet
On Error Resume Next
Dim logRng As Range
checkForLog
Set logRng = Worksheets("ErrorLog").Range("A2")
logRng.EntireRow.Insert
logRng.Cells(0, 1).Value = Now
logRng.Cells(0, 2).Value = subOrFuncName
logRng.Cells(0, 3).Value = lineNum
logRng.Cells(0, 4).Value = description
logRng.Cells(0, 5).Value = number
Worksheets("ErrorLog").Rows(200).Delete
End Sub
Private Sub checkForLog()
'checks for the existance of the errorLog worksheet and creates it if needed
Dim errorLog As Worksheet
On Error GoTo noSheet
Set errorLog = Worksheets("ErrorLog")
Exit Sub
noSheet:
On Error Resume Next
Application.ScreenUpdating = False
Worksheets.Add(After:=Worksheets(Worksheets.count)).name = "ErrorLog"
With Range("ErrorLog!A1")
.Value = "Error Date / Time"
.EntireColumn.ColumnWidth = 15
.EntireColumn.HorizontalAlignment = xlLeft
.Cells(1, 2).Value = "Sub or Function Name"
.Cells(1, 2).EntireColumn.AutoFit
.Cells(1, 2).EntireColumn.ColumnWidth = 25
.Cells(1, 2).EntireColumn.HorizontalAlignment = xlLeft
.Cells(1, 3).Value = "Line Number"
.Cells(1, 3).EntireColumn.AutoFit
.Cells(1, 3).EntireColumn.ColumnWidth = 15
.Cells(1, 3).EntireColumn.HorizontalAlignment = xlLeft
.Cells(1, 4).Value = "Description"
.Cells(1, 4).EntireColumn.AutoFit
.Cells(1, 4).EntireColumn.ColumnWidth = 25
.Cells(1, 4).EntireColumn.HorizontalAlignment = xlLeft
.Cells(1, 5).Value = "Error Code"
.Cells(1, 5).EntireColumn.AutoFit
.Cells(1, 5).EntireColumn.ColumnWidth = 15
.Cells(1, 5).EntireColumn.HorizontalAlignment = xlLeft
End With
Worksheets("ErrorLog").Visible = xlSheetVeryHidden
Application.ScreenUpdating = True
End Sub
Public Sub showErrorLog()
On Error GoTo noLog
Worksheets("ErrorLog").Visible = xlSheetVisible
Worksheets("ErrorLog").Select
Exit Sub

noLog:
MsgBox "There are no errors to display"
End Sub


wow way to complex for me (full of the cold)

why do you need whole numbers

is it for show or some calculation on the sheet

here to talk

Reply With Quote
  #3  
Old December 25th, 2011, 11:54 PM
mounika mounika is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Posts: 2 mounika User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 2 sec
Reputation Power: 0
hii, yes we need whole numbers for some calculation purpose ,actually we wrote the code in an event worksheet change as u see the below red color code..but the error log is supressing the code and the sheet is hanging ,is there any possibility of writing the code that doest not accept decimals while copy/paste ...

Many thanks for your reply

Mounika

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > COPY/Paste of decimal values in sheet

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap