![]() |
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 |
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 |
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 |
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 |
All times are GMT +1. The time now is 02:48 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com