Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Delete Row Select Case

I am trying to get this code to delete every row if the value in
column B begins with "X1".

I'm getting a syntax error any help would greatly be appreciated

Error here - Select Case Left((c, 2), 2)



Complete code:



Sub DeleteRowCase()
Dim c As Long
Dim LastRow As Long

Application.ScreenUpdating = False
LastRow = Range("C65536").End(xlUp).Row
For c = LastRow To 2 Step -1

Select Case Left((c, 2), 2)

Case Is = "X1": .EntireRow.Delete

Next c

End Select

Application.ScreenUpdating = True


End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Delete Row Select Case

Select Case Left(cells(c, 2).value, 2)

or maybe better:

Select Case ucase(Left(cells(c, 2).value, 2))

And later...

Case Is = "X1": rows(c).Delete
or
Case Is = "X1": cells(c,2).EntireRow.Delete


Little Penny wrote:

I am trying to get this code to delete every row if the value in
column B begins with "X1".

I'm getting a syntax error any help would greatly be appreciated

Error here - Select Case Left((c, 2), 2)

Complete code:

Sub DeleteRowCase()
Dim c As Long
Dim LastRow As Long

Application.ScreenUpdating = False
LastRow = Range("C65536").End(xlUp).Row
For c = LastRow To 2 Step -1

Select Case Left((c, 2), 2)

Case Is = "X1": .EntireRow.Delete

Next c

End Select

Application.ScreenUpdating = True


End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Delete Row Select Case

Thank you Dave.





On Sat, 19 Jan 2008 14:29:29 -0600, Dave Peterson
wrote:

Select Case Left(cells(c, 2).value, 2)

or maybe better:

Select Case ucase(Left(cells(c, 2).value, 2))

And later...

Case Is = "X1": rows(c).Delete
or
Case Is = "X1": cells(c,2).EntireRow.Delete


Little Penny wrote:

I am trying to get this code to delete every row if the value in
column B begins with "X1".

I'm getting a syntax error any help would greatly be appreciated

Error here - Select Case Left((c, 2), 2)

Complete code:

Sub DeleteRowCase()
Dim c As Long
Dim LastRow As Long

Application.ScreenUpdating = False
LastRow = Range("C65536").End(xlUp).Row
For c = LastRow To 2 Step -1

Select Case Left((c, 2), 2)

Case Is = "X1": .EntireRow.Delete

Next c

End Select

Application.ScreenUpdating = True


End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Delete Row Select Case

Question.

I'm not a vba guru but why does the code work with declaring i as a
variable, and what is c?

Thanks




On Sat, 19 Jan 2008 14:51:42 -0600, "Don Guillett"
wrote:

Sub deleteif()
For i = Cells(Rows.count, "c").End(xlUp).Row To 2 Step -1
Select Case UCase(Left(Cells(i, "c"), 2))
Case Is = "X1": Rows(i).Delete
Case Else
End Select
Next i
End Sub



--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Little Penny" wrote in message
.. .
I am trying to get this code to delete every row if the value in
column B begins with "X1".

I'm getting a syntax error any help would greatly be appreciated

Error here - Select Case Left((c, 2), 2)



Complete code:



Sub DeleteRowCase()
Dim c As Long
Dim LastRow As Long

Application.ScreenUpdating = False
LastRow = Range("C65536").End(xlUp).Row
For c = LastRow To 2 Step -1

Select Case Left((c, 2), 2)

Case Is = "X1": .EntireRow.Delete

Next c

End Select

Application.ScreenUpdating = True


End Sub



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Delete Row Select Case



I just copied and pasted the code.I just don't understand why the
code worked without dim i as long.


Sub deleteif()
For i = Cells(Rows.count, "c").End(xlUp).Row To 2 Step -1
Select Case UCase(Left(Cells(i, "c"), 2))
Case Is = "X1": Rows(i).Delete
Case Else
End Select
Next i
End Sub





On Sun, 20 Jan 2008 12:11:03 -0600, "Don Guillett"
wrote:


dim i as long
"c" meant column c

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Delete Row Select Case

It's always good practice to declare your variables--but you don't absolutely
need to.

If you don't declare the variable, then excel/vba will make it a Variant
--just like if you explicitly did: Dim i as Variant

(I thought you wanted column B???)

Little Penny wrote:

I just copied and pasted the code.I just don't understand why the
code worked without dim i as long.

Sub deleteif()
For i = Cells(Rows.count, "c").End(xlUp).Row To 2 Step -1
Select Case UCase(Left(Cells(i, "c"), 2))
Case Is = "X1": Rows(i).Delete
Case Else
End Select
Next i
End Sub

On Sun, 20 Jan 2008 12:11:03 -0600, "Don Guillett"
wrote:


dim i as long
"c" meant column c


--

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
Case without Select Case error problem Ayo Excel Discussion (Misc queries) 2 May 16th 08 03:48 PM
how to use select case Junior728 Excel Programming 5 May 15th 07 10:17 AM
End Select without Select Case, Block If without End If errors Atreides Excel Programming 12 November 17th 06 05:10 PM
Case Select Kelly Excel Programming 6 March 16th 05 01:29 PM


All times are GMT +1. The time now is 03:44 AM.

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"