Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Delete a row

Am trying to have this request a date from the user, and then delete all
rows of data prior to that date. Any suggestions? I get a run time error on
the a.EntireRow.Delete code.

Sub DeleteDates()
Dim TempString As String
TempString = InputBox("Enter beginning Date", "Beginning of Date
Range")
If Not TempString = "" Then
msg = "Removing Data prior to - " & TempString & " , Are you Sure
this is the Correct Date?"
DialogStyle = vbYesNo + vbExclamation + vbDefaultButton1
Title = "Is this the Correct Date?"
Response = MsgBox(msg, DialogStyle, Title)
End If
If Response = vbYes Then
GoTo DeleteData
Else
GoTo Aborted
End If
DeleteData:
For a = 1000 To 2 Step -1
If Cells(2, a).Value < TempString Then a.EntireRow.Delete
Next a
Aborted:
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 691
Default Delete a row

Hi John,

a is a row number your formula is invalid try
Cells(2,a).EntireRow.Delete
or a little better
Rows(a).Delete
I would recommend that you DIMension your variables.

For a = 1000 To 2 Step -1
If Cells(2, a).Value < TempString Then a.EntireRow.Delete
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"John Keturi" wrote in message news:VeZhd.91854$hj.32175@fed1read07...
Am trying to have this request a date from the user, and then delete all
rows of data prior to that date. Any suggestions? I get a run time error on
the a.EntireRow.Delete code.

Sub DeleteDates()
Dim TempString As String
TempString = InputBox("Enter beginning Date", "Beginning of Date
Range")
If Not TempString = "" Then
msg = "Removing Data prior to - " & TempString & " , Are you Sure
this is the Correct Date?"
DialogStyle = vbYesNo + vbExclamation + vbDefaultButton1
Title = "Is this the Correct Date?"
Response = MsgBox(msg, DialogStyle, Title)
End If
If Response = vbYes Then
GoTo DeleteData
Else
GoTo Aborted
End If
DeleteData:
For a = 1000 To 2 Step -1
If Cells(2, a).Value < TempString Then a.EntireRow.Delete
Next a
Aborted:
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Delete a row

"John Keturi" schreef in bericht
news:VeZhd.91854$hj.32175@fed1read07...
Am trying to have this request a date from the user, and then delete all
rows of data prior to that date. Any suggestions? I get a run time error

on
the a.EntireRow.Delete code.

Sub DeleteDates()
Dim TempString As String
TempString = InputBox("Enter beginning Date", "Beginning of Date
Range")
If Not TempString = "" Then
msg = "Removing Data prior to - " & TempString & " , Are you Sure
this is the Correct Date?"
DialogStyle = vbYesNo + vbExclamation + vbDefaultButton1
Title = "Is this the Correct Date?"
Response = MsgBox(msg, DialogStyle, Title)
End If
If Response = vbYes Then
GoTo DeleteData
Else
GoTo Aborted
End If
DeleteData:
For a = 1000 To 2 Step -1
If Cells(2, a).Value < TempString Then a.EntireRow.Delete
Next a
Aborted:
End Sub



You are referring to Cells(2,a), which means (2,1000) the first time. But
Excel has only 256 columns so I think you're confusing rows and columns and
columns and rows.
Maybe Cells(a,2) works better...


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Delete a row

Wow. Fast Usenet refresh I have...


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 691
Default Delete a row


You are referring to Cells(2,a), which means (2,1000) the first time. But
Excel has only 256 columns so I think you're confusing rows and columns and
columns and rows.
Maybe Cells(a,2) works better...


missed that and even repeated the mistake.


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 to Delete a Range in Closed Workbook (to Replace Delete Query) [email protected] Excel Discussion (Misc queries) 1 March 8th 06 10:10 AM
How do i delete a macro in Excel 2003 when delete isn't highlight Abel Excel Discussion (Misc queries) 2 September 13th 05 04:09 AM
How to delete rows when List toolbar's "delete" isnt highlighted? Linda Excel Worksheet Functions 1 May 26th 05 08:39 PM
Delete every 3rd row, then delete rows 2-7, move info f/every 2nd row up one to the end and delete the row below Annette[_4_] Excel Programming 2 September 21st 04 02:40 PM


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