Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default skip some code

I know it's heresy to branch. So how do I handle this situation? I have
some code taking a date from a cell and doing a MONTH command to
extract the month and process based on that month number. Sometimes,
the cell that normally contains the date contains text like "na" or
"?". Then I get a type mismatch error on this line:

dteColCode = rngColCode.Value

How can I instruct it to skip down to the line "Next rCell" if an error
occurs on this line?
Thanks for your help.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default skip some code

Shoule have mentioned that dteColCode is dimmed as date, rngColCode is
dimmed as range...

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default skip some code

Option Explicit
Sub testme()

Dim dteColCode As Variant
Dim rngColCode As Range

Set rngColCode = ActiveSheet.Range("a1")

dteColCode = rngColCode.Value
If IsDate(dteColCode) Then
'do your stuff
MsgBox "it looks like a date"
Else
'skip it
MsgBox "not a date"
End If

End Sub

davegb wrote:

I know it's heresy to branch. So how do I handle this situation? I have
some code taking a date from a cell and doing a MONTH command to
extract the month and process based on that month number. Sometimes,
the cell that normally contains the date contains text like "na" or
"?". Then I get a type mismatch error on this line:

dteColCode = rngColCode.Value

How can I instruct it to skip down to the line "Next rCell" if an error
occurs on this line?
Thanks for your help.


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default skip some code


Dave Peterson wrote:
Option Explicit
Sub testme()

Dim dteColCode As Variant
Dim rngColCode As Range

Set rngColCode = ActiveSheet.Range("a1")

dteColCode = rngColCode.Value
If IsDate(dteColCode) Then
'do your stuff
MsgBox "it looks like a date"
Else
'skip it
MsgBox "not a date"
End If

End Sub

davegb wrote:

I know it's heresy to branch. So how do I handle this situation? I have
some code taking a date from a cell and doing a MONTH command to
extract the month and process based on that month number. Sometimes,
the cell that normally contains the date contains text like "na" or
"?". Then I get a type mismatch error on this line:

dteColCode = rngColCode.Value

How can I instruct it to skip down to the line "Next rCell" if an error
occurs on this line?
Thanks for your help.


--

Dave Peterson


Dave, thanks again. I changed the macro, but I'm still having a problem
with the cell that normally has a date in it is blank.

Sub CountMonth()

Dim lngRsnCode As Long
Dim wksSrc As Worksheet
Dim wksMon As Worksheet
Dim wksTot As Worksheet
Dim rngCode As Range
Dim lEndRow As Long
Dim strMonWksht As String
Dim dteColCode As Date

Dim lngCntctMo As Long
Dim lngMoRow As Long
Dim rngCell As Range
Dim varColCode As Variant
Dim strColCode As String


Const PWORD As String = "2005totals"
lEndRow = 1000

Set wksSrc = ActiveSheet
Set wksTot = ActiveWorkbook.Sheets("TOTALS")
Set rngCode = wksSrc.Range("D8:D" & lEndRow)
wksTot.Unprotect Password:=PWORD

strMonWksht = wksSrc.Name & " - Monthly"
Set wksMon = Sheets(strMonWksht)

wksMon.Range("B4:K15").ClearContents

For Each rngCell In rngCode
rngCell.Select

If rngCell < "na" Then
If rngCell < "?" Then
If Len(rngCell) < 3 Then
If rngCell < 0 Then
If rngCell < 11 Then
If rngCell < 15 Then
If rngCell < "" Then
Set varColCode = rngCell.Offset(0, 5)
If varColCode.Value < "" Then <-- not doing what I want it to
do
dteColCode = varColCode.Value<--- TYPE MISMATCH
If IsDate(dteColCode) Then
lngCntctMo = Month(dteColCode)
lngMoRow = lngCntctMo + 3
lngRsnCode = rngCell
wksTot.Range("AC1") = lngRsnCode
strColCode = wksTot.Range("AC2")
wksMon.Cells(lngMoRow, strColCode) = _
wksMon.Cells(lngMoRow, strColCode) + 1
End If
End If
End If
End If
End If
End If
End If
End If
End If

Next rngCell

wksTot.Protect Password:=PWORD
wksTot.Select

End Sub

The line above the error (marked "not doing what I want it to do") is
supposed to check for a blank cell, and bypass the rest of the
instructions if it is and go to "Next rngCell". I think this is what is
giving me the type mismatch on the next line. Any suggestions?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default skip some code

For Each rngCell In rngCode
rngCell.Select

If rngCell < "na" Then
If rngCell < "?" Then
If Len(rngCell) < 3 Then
If rngCell < 0 Then
If rngCell < 11 Then
If rngCell < 15 Then
If rngCell < "" Then
Set varColCode = rngCell.Offset(0, 5)
If Trim(varColCode.Text) < "" Then
dteColCode = varColCode.Value
If IsDate(dteColCode) Then
lngCntctMo = Month(dteColCode)
lngMoRow = lngCntctMo + 3
lngRsnCode = rngCell
wksTot.Range("AC1") = lngRsnCode
strColCode = wksTot.Range("AC2")
wksMon.Cells(lngMoRow, strColCode) = _
wksMon.Cells(lngMoRow, strColCode) + 1
End If
End If
End If
End If
End If
End If
End If
End If
End If

--
Regards,
Tom Ogilvy

"davegb" wrote in message
oups.com...

Dave Peterson wrote:
Option Explicit
Sub testme()

Dim dteColCode As Variant
Dim rngColCode As Range

Set rngColCode = ActiveSheet.Range("a1")

dteColCode = rngColCode.Value
If IsDate(dteColCode) Then
'do your stuff
MsgBox "it looks like a date"
Else
'skip it
MsgBox "not a date"
End If

End Sub

davegb wrote:

I know it's heresy to branch. So how do I handle this situation? I

have
some code taking a date from a cell and doing a MONTH command to
extract the month and process based on that month number. Sometimes,
the cell that normally contains the date contains text like "na" or
"?". Then I get a type mismatch error on this line:

dteColCode = rngColCode.Value

How can I instruct it to skip down to the line "Next rCell" if an

error
occurs on this line?
Thanks for your help.


--

Dave Peterson


Dave, thanks again. I changed the macro, but I'm still having a problem
with the cell that normally has a date in it is blank.

Sub CountMonth()

Dim lngRsnCode As Long
Dim wksSrc As Worksheet
Dim wksMon As Worksheet
Dim wksTot As Worksheet
Dim rngCode As Range
Dim lEndRow As Long
Dim strMonWksht As String
Dim dteColCode As Date

Dim lngCntctMo As Long
Dim lngMoRow As Long
Dim rngCell As Range
Dim varColCode As Variant
Dim strColCode As String


Const PWORD As String = "2005totals"
lEndRow = 1000

Set wksSrc = ActiveSheet
Set wksTot = ActiveWorkbook.Sheets("TOTALS")
Set rngCode = wksSrc.Range("D8:D" & lEndRow)
wksTot.Unprotect Password:=PWORD

strMonWksht = wksSrc.Name & " - Monthly"
Set wksMon = Sheets(strMonWksht)

wksMon.Range("B4:K15").ClearContents

For Each rngCell In rngCode
rngCell.Select

If rngCell < "na" Then
If rngCell < "?" Then
If Len(rngCell) < 3 Then
If rngCell < 0 Then
If rngCell < 11 Then
If rngCell < 15 Then
If rngCell < "" Then
Set varColCode = rngCell.Offset(0, 5)
If varColCode.Value < "" Then <-- not doing what I want it to
do
dteColCode = varColCode.Value<--- TYPE MISMATCH
If IsDate(dteColCode) Then
lngCntctMo = Month(dteColCode)
lngMoRow = lngCntctMo + 3
lngRsnCode = rngCell
wksTot.Range("AC1") = lngRsnCode
strColCode = wksTot.Range("AC2")
wksMon.Cells(lngMoRow, strColCode) = _
wksMon.Cells(lngMoRow, strColCode) + 1
End If
End If
End If
End If
End If
End If
End If
End If
End If

Next rngCell

wksTot.Protect Password:=PWORD
wksTot.Select

End Sub

The line above the error (marked "not doing what I want it to do") is
supposed to check for a blank cell, and bypass the rest of the
instructions if it is and go to "Next rngCell". I think this is what is
giving me the type mismatch on the next line. Any suggestions?





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default skip some code

Thanks again, Tom!

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
Can I Skip a row in my formula? RaY Excel Worksheet Functions 3 August 19th 08 01:12 PM
using IF to skip Julie Excel Worksheet Functions 4 March 14th 08 10:21 PM
Excel VBA macro - need to edit code to skip a year adun3434 Excel Programming 0 April 1st 04 09:14 PM
skip code monika Excel Programming 1 February 26th 04 02:33 AM
Excel skip some lines of VBA code Alex[_7_] Excel Programming 1 August 28th 03 12:18 PM


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