first macro


Posted by kathleen on January 30, 2001 6:28 AM

hello


very simple for most of you, but this is first writing in visual basic

i want to delete 17 rows every 24 rows of data, to finish with 8760 rows of data

this is my code for macro erase17, something is wrong....


Sub erase17()
'
' erase17 Macro
' Macro enregistrée le 1/30/2001 par Cenerg
'

'

For q = 25 To 8737 Step 24
y = q + 25
Rows("q:y").Select
Selection.Delete Shift:=xlUp
Next q


End Sub

I do not know if and how you declare variables in visual basic, i can only code in C. i continue to get an error on the line


Rows("q:y").Select

thanks in advance

kph

Posted by Gregc on January 30, 2001 7:45 AM

erase17 Macro Macro enregistrée le 1/30/2001 par Cenerg ' For q = 25 To 8737 Step 24

response: to declare a variable use the DIM statement at the beginning of the macro.
DIM Q as int

This should work for your range selection
Range("a"&q, "a"&y ).EntireRow.Select
Then do you delete.
Hope that helps.




Posted by Celia on January 30, 2001 7:57 AM

erase17 Macro Macro enregistrée le 1/30/2001 par Cenerg ' For q = 25 To 8737 Step 24


Change to :- Rows(q & ":" & y)

However, if you want to delete 17 rows of data every 24 rows starting at row 25, try this :-

Sub erase17()
Dim x%, y%, r As Range
For x = 25 To 8737 Step 24
If y = 0 Then
Set r = Rows(x).Resize(17)
y = 1
Else
Set r = Union(r, Rows(x).Resize(17))
End If
Next
r.Delete
End Sub

Celia