Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default sub for deleting data on a sheet in a range

I need a sub procedure that deletes data on a definited sheet in a definited
unnamed range(and only if background of the cell is yellow). I tried to
write it but it doesn't work. When I call the sub procedure, visual basic
says "syntax error" :( does anyone know why?

Private Sub delete_data(sheet as string, ra, rb, column as integer)
With Worksheets(sheet)
For index = ra To rb
If .Cells(index, column).Interior.ColorIndex = 6 Then
.Cells(index, column) = ""
End If
Next index
End With
End Sub

Private Sub cmdButton_Click()
delete_data("shtHM",7,23,3)
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 279
Default sub for deleting data on a sheet in a range

Your variable names are likely the problem
index
column
sheet
these are defined terms in VBA and you are trying to use them for variables

try myIndex, mycColumn, mySheet

also might use
.Cells(myindex, mycolumn).clearcontents

"Buddy Lee" wrote:

I need a sub procedure that deletes data on a definited sheet in a definited
unnamed range(and only if background of the cell is yellow). I tried to
write it but it doesn't work. When I call the sub procedure, visual basic
says "syntax error" :( does anyone know why?

Private Sub delete_data(sheet as string, ra, rb, column as integer)
With Worksheets(sheet)
For index = ra To rb
If .Cells(index, column).Interior.ColorIndex = 6 Then
.Cells(index, column) = ""
End If
Next index
End With
End Sub

Private Sub cmdButton_Click()
delete_data("shtHM",7,23,3)
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default sub for deleting data on a sheet in a range

"sheet", "index" and "column" aren't the best choices for variable names.
Not sure if they are actually reserved words in VBA, but still best avoided.

You don't need () when calling a sub

delete_data "shtHM", 7, 23, 3


Tim

--
Tim Williams
Palo Alto, CA


"Buddy Lee" wrote in message
...
I need a sub procedure that deletes data on a definited sheet in a

definited
unnamed range(and only if background of the cell is yellow). I tried to
write it but it doesn't work. When I call the sub procedure, visual basic
says "syntax error" :( does anyone know why?

Private Sub delete_data(sheet as string, ra, rb, column as integer)
With Worksheets(sheet)
For index = ra To rb
If .Cells(index, column).Interior.ColorIndex = 6 Then
.Cells(index, column) = ""
End If
Next index
End With
End Sub

Private Sub cmdButton_Click()
delete_data("shtHM",7,23,3)
End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default sub for deleting data on a sheet in a range

You don't need () when calling a sub


that's it, thank you :)


"Tim Williams" <timjwilliams at gmail dot com píše v diskusním příspěvku
...
"sheet", "index" and "column" aren't the best choices for variable names.
Not sure if they are actually reserved words in VBA, but still best
avoided.

You don't need () when calling a sub

delete_data "shtHM", 7, 23, 3


Tim

--
Tim Williams
Palo Alto, CA


"Buddy Lee" wrote in message
...
I need a sub procedure that deletes data on a definited sheet in a

definited
unnamed range(and only if background of the cell is yellow). I tried to
write it but it doesn't work. When I call the sub procedure, visual basic
says "syntax error" :( does anyone know why?

Private Sub delete_data(sheet as string, ra, rb, column as integer)
With Worksheets(sheet)
For index = ra To rb
If .Cells(index, column).Interior.ColorIndex = 6 Then
.Cells(index, column) = ""
End If
Next index
End With
End Sub

Private Sub cmdButton_Click()
delete_data("shtHM",7,23,3)
End Sub






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
How do I copy a range of data to another sheet? MrNobody Excel Worksheet Functions 2 February 19th 09 03:38 AM
Extracting/deleting select data from range of cell DipyDawg Excel Discussion (Misc queries) 4 May 6th 08 06:48 PM
how to transfer data from sheet to sheet with new range? Jon Excel Discussion (Misc queries) 6 August 20th 07 06:36 PM
Deleting cell data without deleting formula Tom Hall Excel Discussion (Misc queries) 4 October 29th 06 04:07 PM
Deleting Range name's listed in the range address box. Satnam Patel Excel Discussion (Misc queries) 4 May 5th 05 01:42 PM


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