Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default type mismatch in this code

I am scanning a column in sheet1 and looking for "Closed" or "Cancelled
If i find closed or cancelled, the whole row that it finds it on gets moved to sheet2
After that... Any row that contained "Closed" or "cancelled" gets deleted from sheet1

When i run the macro I get "Type Mismatch 13" on "If ws1.Cells(iRow1, 28) = "Closed" Or "Cancelled" Then". The same error would occur in "If ws1.Cells(iCt, 28) = "Closed" Or "Cancelled" Then ws1.Rows(iCt).Delete

If i remove the ---Or "Cancelled" in both places, the function works and searches for closed only. But i need it to look for cancelled items too. Any help would be greatly appreciated

This is the code i'm using

Sub ClosedRoutine(

Dim iCt As Intege
Dim iRow1 As Intege
Dim iRow2 As Intege
Dim ws1 As Workshee
Dim ws2 As Workshee
Dim erow As Intege

Set ws1 = Sheets("Sheet1"
Set ws2 = Sheets("Sheet2"
iRow1 =
erow =
While ws2.Cells(erow, 28) < "": erow = erow + 1: Wen
iRow2 = ero

'copy from sheet1 to sheet
Do Until ws1.Cells(iRow1, 28) = "END
If ws1.Cells(iRow1, 28) = "Closed" Or "Cancelled" The
For iCt = 1 To 2
ws2.Cells(iRow2, iCt) = ws1.Cells(iRow1, iCt
Next iC
iRow2 = iRow2 +
End I
iRow1 = iRow1 +
Loo

'delete from sheet
For iCt = iRow1 To 2 Step -
If ws1.Cells(iCt, 28) = "Closed" Or "Cancelled" Then ws1.Rows(iCt).Delet
Next iC

End Su

Thanks
Jay Baxte

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default type mismatch in this code

Jay,

Change

If ws1.Cells(iRow1, 28) = "Closed" Or "Cancelled" Then

to

If ws1.Cells(iRow1, 28) = "Closed" Or .Cells(iRow1, 28)
="Cancelled" Then



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Jay Baxter" wrote in
message
...
I am scanning a column in sheet1 and looking for "Closed" or

"Cancelled"
If i find closed or cancelled, the whole row that it finds it

on gets moved to sheet2.
After that... Any row that contained "Closed" or "cancelled"

gets deleted from sheet1.

When i run the macro I get "Type Mismatch 13" on "If

ws1.Cells(iRow1, 28) = "Closed" Or "Cancelled" Then". The same
error would occur in "If ws1.Cells(iCt, 28) = "Closed" Or
"Cancelled" Then ws1.Rows(iCt).Delete"

If i remove the ---Or "Cancelled" in both places, the function

works and searches for closed only. But i need it to look for
cancelled items too. Any help would be greatly appreciated.


This is the code i'm using:

Sub ClosedRoutine()

Dim iCt As Integer
Dim iRow1 As Integer
Dim iRow2 As Integer
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim erow As Integer

Set ws1 = Sheets("Sheet1")
Set ws2 = Sheets("Sheet2")
iRow1 = 6
erow = 5
While ws2.Cells(erow, 28) < "": erow = erow + 1: Wend
iRow2 = erow

'copy from sheet1 to sheet2
Do Until ws1.Cells(iRow1, 28) = "END"
If ws1.Cells(iRow1, 28) = "Closed" Or "Cancelled" Then
For iCt = 1 To 29
ws2.Cells(iRow2, iCt) = ws1.Cells(iRow1, iCt)
Next iCt
iRow2 = iRow2 + 1
End If
iRow1 = iRow1 + 1
Loop

'delete from sheet1
For iCt = iRow1 To 2 Step -1
If ws1.Cells(iCt, 28) = "Closed" Or "Cancelled" Then

ws1.Rows(iCt).Delete
Next iCt

End Sub


Thanks,
Jay Baxter



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default type mismatch in this code

You're using the "Or" operator improperly. You need to
include the expression both times:

If ws1.Cells(iRow1, 28) = "Closed" Or ws1.Cells(iRow1, 28)
= "Cancelled" Then

-Brad
-----Original Message-----
I am scanning a column in sheet1 and looking for "Closed"

or "Cancelled"
If i find closed or cancelled, the whole row that it

finds it on gets moved to sheet2.
After that... Any row that contained "Closed"

or "cancelled" gets deleted from sheet1.

When i run the macro I get "Type Mismatch 13" on "If

ws1.Cells(iRow1, 28) = "Closed" Or "Cancelled" Then". The
same error would occur in "If ws1.Cells(iCt, 28)
= "Closed" Or "Cancelled" Then ws1.Rows(iCt).Delete"

If i remove the ---Or "Cancelled" in both places, the

function works and searches for closed only. But i need
it to look for cancelled items too. Any help would be
greatly appreciated.


This is the code i'm using:

Sub ClosedRoutine()

Dim iCt As Integer
Dim iRow1 As Integer
Dim iRow2 As Integer
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim erow As Integer

Set ws1 = Sheets("Sheet1")
Set ws2 = Sheets("Sheet2")
iRow1 = 6
erow = 5
While ws2.Cells(erow, 28) < "": erow = erow + 1: Wend
iRow2 = erow

'copy from sheet1 to sheet2
Do Until ws1.Cells(iRow1, 28) = "END"
If ws1.Cells(iRow1, 28) = "Closed" Or "Cancelled" Then
For iCt = 1 To 29
ws2.Cells(iRow2, iCt) = ws1.Cells(iRow1, iCt)
Next iCt
iRow2 = iRow2 + 1
End If
iRow1 = iRow1 + 1
Loop

'delete from sheet1
For iCt = iRow1 To 2 Step -1
If ws1.Cells(iCt, 28) = "Closed" Or "Cancelled" Then

ws1.Rows(iCt).Delete
Next iCt

End Sub


Thanks,
Jay Baxter

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default type mismatch in this code

Thank you Chip

It worked like a charm

Jay Baxter
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default type mismatch in this code

Thanks Brad

I got it working now. I'm not too familiar with VB syntax.. But alas all works for now hehe

Jay
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
[Q] Save As throws type mismatch error in control's code? Jason Weiss Excel Discussion (Misc queries) 1 July 16th 05 04:21 AM
Type Mismatch Edgar[_3_] Excel Programming 4 February 13th 04 03:55 PM
Code works 1st time then Type Mismatch when checking for not blank cells Colleyville Alan Excel Programming 3 February 6th 04 05:21 AM
Type mismatch Steve Garman Excel Programming 0 February 5th 04 07:39 AM


All times are GMT +1. The time now is 04:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"