Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Please help with my code

Hello all,

I have 2 worksheets, "Sheet 1" and "Sheet 2". First, my code checks the
length of Cell "E26" in "Sheet 1". If the length of E26 is not equal to 6,
delete the records (entire row) in "Sheet 2" with the values "A-1", "B-1" and
"C-1" in column F of Sheet 2. Then move the records up that are below.

The Sheet 2 has over 1000 records and has 10 columns with values. I have
the following code, and when I executed it, I got a Type Mismatch error, and
it pointed me to the line "If s2Record = "A-1" or s2Record = "B-1" or
s2Record = "C-1" Then".

If Len(Sheets("Sheet 1").Range("E26")) < 6 Then
For Each s2Record in Worksheets("Sheet 2").Columns(6)
If s2Record = "A-1" or s2Record = "B-1" or s2Record = "C-1" Then
s2Record.EntireRow.Delete Shift:=xlShiftUp
end if
Next s2Record
End If

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Please help with my code

For each and deleting do not get along. You will be deleting s2Record which
is an issue, not to mention that the sive of the range you are traversing
will be changing. What you can do (whis is much more efficint eany ways is to
create on big range to be deleted at the end after the for each is done...
something like this...

Dim rngToDelete As Range
Dim s2Record As Range

If Len(Sheets("Sheet 1").Range("E26")) < 6 Then
For Each s2Record In Worksheets("Sheet 2").Columns(6)
With s2Record
If .Value = "A-1" Or .Value = "B-1" Or .Value = "C-1" Then
If rngToDelete Is Nothing Then
Set rngToDelete = s2Record
Else
Set rngToDelete = Union(rngToDelete, s2Record)
End If
End With
Next s2Record
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
End If
--
HTH...

Jim Thomlinson


"Please Help" wrote:

Hello all,

I have 2 worksheets, "Sheet 1" and "Sheet 2". First, my code checks the
length of Cell "E26" in "Sheet 1". If the length of E26 is not equal to 6,
delete the records (entire row) in "Sheet 2" with the values "A-1", "B-1" and
"C-1" in column F of Sheet 2. Then move the records up that are below.

The Sheet 2 has over 1000 records and has 10 columns with values. I have
the following code, and when I executed it, I got a Type Mismatch error, and
it pointed me to the line "If s2Record = "A-1" or s2Record = "B-1" or
s2Record = "C-1" Then".

If Len(Sheets("Sheet 1").Range("E26")) < 6 Then
For Each s2Record in Worksheets("Sheet 2").Columns(6)
If s2Record = "A-1" or s2Record = "B-1" or s2Record = "C-1" Then
s2Record.EntireRow.Delete Shift:=xlShiftUp
end if
Next s2Record
End If

Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Please help with my code

Hi Jim,

Thanks for the code. When I tried your code, I got an error message "End
With without With", and it pointed me to the line "End With" in your code.

Do you know why?

Thanks.

"Jim Thomlinson" wrote:

For each and deleting do not get along. You will be deleting s2Record which
is an issue, not to mention that the sive of the range you are traversing
will be changing. What you can do (whis is much more efficint eany ways is to
create on big range to be deleted at the end after the for each is done...
something like this...

Dim rngToDelete As Range
Dim s2Record As Range

If Len(Sheets("Sheet 1").Range("E26")) < 6 Then
For Each s2Record In Worksheets("Sheet 2").Columns(6)
With s2Record
If .Value = "A-1" Or .Value = "B-1" Or .Value = "C-1" Then
If rngToDelete Is Nothing Then
Set rngToDelete = s2Record
Else
Set rngToDelete = Union(rngToDelete, s2Record)
End If
End With
Next s2Record
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
End If
--
HTH...

Jim Thomlinson


"Please Help" wrote:

Hello all,

I have 2 worksheets, "Sheet 1" and "Sheet 2". First, my code checks the
length of Cell "E26" in "Sheet 1". If the length of E26 is not equal to 6,
delete the records (entire row) in "Sheet 2" with the values "A-1", "B-1" and
"C-1" in column F of Sheet 2. Then move the records up that are below.

The Sheet 2 has over 1000 records and has 10 columns with values. I have
the following code, and when I executed it, I got a Type Mismatch error, and
it pointed me to the line "If s2Record = "A-1" or s2Record = "B-1" or
s2Record = "C-1" Then".

If Len(Sheets("Sheet 1").Range("E26")) < 6 Then
For Each s2Record in Worksheets("Sheet 2").Columns(6)
If s2Record = "A-1" or s2Record = "B-1" or s2Record = "C-1" Then
s2Record.EntireRow.Delete Shift:=xlShiftUp
end if
Next s2Record
End If

Thanks.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Please help with my code

Jim missed an "end if" statement:

Dim rngToDelete As Range
Dim s2Record As Range

If Len(Sheets("Sheet 1").Range("E26")) < 6 Then
For Each s2Record In Worksheets("Sheet 2").Columns(6)
With s2Record
If .Value = "A-1" Or .Value = "B-1" Or .Value = "C-1" Then
If rngToDelete Is Nothing Then
Set rngToDelete = s2Record
Else
Set rngToDelete = Union(rngToDelete, s2Record)
End if '<--Added here
End If
End With
Next s2Record
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
End If

Please Help wrote:

Hi Jim,

Thanks for the code. When I tried your code, I got an error message "End
With without With", and it pointed me to the line "End With" in your code.

Do you know why?

Thanks.

"Jim Thomlinson" wrote:

For each and deleting do not get along. You will be deleting s2Record which
is an issue, not to mention that the sive of the range you are traversing
will be changing. What you can do (whis is much more efficint eany ways is to
create on big range to be deleted at the end after the for each is done...
something like this...

Dim rngToDelete As Range
Dim s2Record As Range

If Len(Sheets("Sheet 1").Range("E26")) < 6 Then
For Each s2Record In Worksheets("Sheet 2").Columns(6)
With s2Record
If .Value = "A-1" Or .Value = "B-1" Or .Value = "C-1" Then
If rngToDelete Is Nothing Then
Set rngToDelete = s2Record
Else
Set rngToDelete = Union(rngToDelete, s2Record)
End If
End With
Next s2Record
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
End If
--
HTH...

Jim Thomlinson


"Please Help" wrote:

Hello all,

I have 2 worksheets, "Sheet 1" and "Sheet 2". First, my code checks the
length of Cell "E26" in "Sheet 1". If the length of E26 is not equal to 6,
delete the records (entire row) in "Sheet 2" with the values "A-1", "B-1" and
"C-1" in column F of Sheet 2. Then move the records up that are below.

The Sheet 2 has over 1000 records and has 10 columns with values. I have
the following code, and when I executed it, I got a Type Mismatch error, and
it pointed me to the line "If s2Record = "A-1" or s2Record = "B-1" or
s2Record = "C-1" Then".

If Len(Sheets("Sheet 1").Range("E26")) < 6 Then
For Each s2Record in Worksheets("Sheet 2").Columns(6)
If s2Record = "A-1" or s2Record = "B-1" or s2Record = "C-1" Then
s2Record.EntireRow.Delete Shift:=xlShiftUp
end if
Next s2Record
End If

Thanks.


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Please help with my code

Hi Dave,

Thanks for your response. I added "End If" per your instruction, and I got
another error message "Type Mismatch".

Any idea?

Thanks.

"Dave Peterson" wrote:

Jim missed an "end if" statement:

Dim rngToDelete As Range
Dim s2Record As Range

If Len(Sheets("Sheet 1").Range("E26")) < 6 Then
For Each s2Record In Worksheets("Sheet 2").Columns(6)
With s2Record
If .Value = "A-1" Or .Value = "B-1" Or .Value = "C-1" Then
If rngToDelete Is Nothing Then
Set rngToDelete = s2Record
Else
Set rngToDelete = Union(rngToDelete, s2Record)
End if '<--Added here
End If
End With
Next s2Record
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
End If

Please Help wrote:

Hi Jim,

Thanks for the code. When I tried your code, I got an error message "End
With without With", and it pointed me to the line "End With" in your code.

Do you know why?

Thanks.

"Jim Thomlinson" wrote:

For each and deleting do not get along. You will be deleting s2Record which
is an issue, not to mention that the sive of the range you are traversing
will be changing. What you can do (whis is much more efficint eany ways is to
create on big range to be deleted at the end after the for each is done...
something like this...

Dim rngToDelete As Range
Dim s2Record As Range

If Len(Sheets("Sheet 1").Range("E26")) < 6 Then
For Each s2Record In Worksheets("Sheet 2").Columns(6)
With s2Record
If .Value = "A-1" Or .Value = "B-1" Or .Value = "C-1" Then
If rngToDelete Is Nothing Then
Set rngToDelete = s2Record
Else
Set rngToDelete = Union(rngToDelete, s2Record)
End If
End With
Next s2Record
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
End If
--
HTH...

Jim Thomlinson


"Please Help" wrote:

Hello all,

I have 2 worksheets, "Sheet 1" and "Sheet 2". First, my code checks the
length of Cell "E26" in "Sheet 1". If the length of E26 is not equal to 6,
delete the records (entire row) in "Sheet 2" with the values "A-1", "B-1" and
"C-1" in column F of Sheet 2. Then move the records up that are below.

The Sheet 2 has over 1000 records and has 10 columns with values. I have
the following code, and when I executed it, I got a Type Mismatch error, and
it pointed me to the line "If s2Record = "A-1" or s2Record = "B-1" or
s2Record = "C-1" Then".

If Len(Sheets("Sheet 1").Range("E26")) < 6 Then
For Each s2Record in Worksheets("Sheet 2").Columns(6)
If s2Record = "A-1" or s2Record = "B-1" or s2Record = "C-1" Then
s2Record.EntireRow.Delete Shift:=xlShiftUp
end if
Next s2Record
End If

Thanks.


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default Please help with my code

Dave,

In addition to my earlier message, the error was pointed me to the same line
that I posted initially (If .value = "A-1" or .value = "B-1" or .value="C-1"
Then).

Thanks.

"Please Help" wrote:

Hi Dave,

Thanks for your response. I added "End If" per your instruction, and I got
another error message "Type Mismatch".

Any idea?

Thanks.

"Dave Peterson" wrote:

Jim missed an "end if" statement:

Dim rngToDelete As Range
Dim s2Record As Range

If Len(Sheets("Sheet 1").Range("E26")) < 6 Then
For Each s2Record In Worksheets("Sheet 2").Columns(6)
With s2Record
If .Value = "A-1" Or .Value = "B-1" Or .Value = "C-1" Then
If rngToDelete Is Nothing Then
Set rngToDelete = s2Record
Else
Set rngToDelete = Union(rngToDelete, s2Record)
End if '<--Added here
End If
End With
Next s2Record
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
End If

Please Help wrote:

Hi Jim,

Thanks for the code. When I tried your code, I got an error message "End
With without With", and it pointed me to the line "End With" in your code.

Do you know why?

Thanks.

"Jim Thomlinson" wrote:

For each and deleting do not get along. You will be deleting s2Record which
is an issue, not to mention that the sive of the range you are traversing
will be changing. What you can do (whis is much more efficint eany ways is to
create on big range to be deleted at the end after the for each is done...
something like this...

Dim rngToDelete As Range
Dim s2Record As Range

If Len(Sheets("Sheet 1").Range("E26")) < 6 Then
For Each s2Record In Worksheets("Sheet 2").Columns(6)
With s2Record
If .Value = "A-1" Or .Value = "B-1" Or .Value = "C-1" Then
If rngToDelete Is Nothing Then
Set rngToDelete = s2Record
Else
Set rngToDelete = Union(rngToDelete, s2Record)
End If
End With
Next s2Record
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
End If
--
HTH...

Jim Thomlinson


"Please Help" wrote:

Hello all,

I have 2 worksheets, "Sheet 1" and "Sheet 2". First, my code checks the
length of Cell "E26" in "Sheet 1". If the length of E26 is not equal to 6,
delete the records (entire row) in "Sheet 2" with the values "A-1", "B-1" and
"C-1" in column F of Sheet 2. Then move the records up that are below.

The Sheet 2 has over 1000 records and has 10 columns with values. I have
the following code, and when I executed it, I got a Type Mismatch error, and
it pointed me to the line "If s2Record = "A-1" or s2Record = "B-1" or
s2Record = "C-1" Then".

If Len(Sheets("Sheet 1").Range("E26")) < 6 Then
For Each s2Record in Worksheets("Sheet 2").Columns(6)
If s2Record = "A-1" or s2Record = "B-1" or s2Record = "C-1" Then
s2Record.EntireRow.Delete Shift:=xlShiftUp
end if
Next s2Record
End If

Thanks.


--

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
split post code (zip code) out of cell that includes full address Concord Excel Discussion (Misc queries) 4 October 15th 09 06:59 PM
Slow code when used as VBA code instead of macro (copying visible columns) [email protected] Excel Programming 3 April 2nd 07 05:26 PM
Shorten code to apply to all sheets except a few, instead of individually naming them, and later adding to code. Corey Excel Programming 3 December 11th 06 05:14 AM
Protect Sheet with code, but then code will not Paste error. How do i get around this. Please read for explainations.... Corey Excel Programming 4 November 25th 06 04:57 AM
Excel code convert to Access code - Concat & eliminate duplicates italia Excel Programming 1 September 12th 06 12:14 AM


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