Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 237
Default Modifying Code that deletes a Row

Hey guys

Happy Thanksgiving.

Here is a code(see below) that deletes the entire row if
Textbox1,2,and3 match data found in a row in range A1:A3
starting in A1.

What would the code be, that would put the number of the
row to be deleted in cell K1, instead of actually deleting
the entire Row that matches the criteria in the 3
textboxes? I dont want to delete the row, just put the
row to be deleted in cell K1.


Private Sub CommandButton6_Click()
If MsgBox("Are you sure?", vbYesNo) = vbNo Then
Exit Sub
End If
Dim c
Dim firstAddress As String, tmp As Integer
Dim tmp_array()

With Worksheets(2)
Set c = .Range("A1").CurrentRegion.Columns(1).Find
(TextBox1.Text, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
If c.Offset(0, 1).Value = TextBox2.Text And
c.Offset(0, 2).Value = TextBox3.Text Then
On Error GoTo err1
ReDim Preserve tmp_array(UBound(tmp_array)
+ 1)
On Error GoTo 0
tmp_array(UBound(tmp_array)) = c.Address
(False, False)
End If
Set c = .Range("A1").CurrentRegion.Columns
(1).FindNext(c)
Loop While Not c Is Nothing And c.Address <
firstAddress
On Error GoTo err2
For tmp = UBound(tmp_array) To 1 Step -1
.Range(tmp_array(tmp)).EntireRow.Delete
Next
End If
End With
Unload Me
MsgBox "1 Record Deleted Successfully", vbOKOnly

err2:
Exit Sub

err1:
ReDim tmp_array(1)
Resume Next
End Sub




Thanx,
Todd
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Modifying Code that deletes a Row

Todd,

This code

For tmp = UBound(tmp_array) To 1 Step -1
.Range(tmp_array(tmp)).EntireRow.Delete
Next

can be replaced by

For tmp = UBound(tmp_array) To 1 Step -1
Range("K1") = .Range(tmp_array(tmp)).Row
Next

but it will get over-written if you find more than 1 occurence.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Todd Huttenstine" wrote in message
...
Hey guys

Happy Thanksgiving.

Here is a code(see below) that deletes the entire row if
Textbox1,2,and3 match data found in a row in range A1:A3
starting in A1.

What would the code be, that would put the number of the
row to be deleted in cell K1, instead of actually deleting
the entire Row that matches the criteria in the 3
textboxes? I dont want to delete the row, just put the
row to be deleted in cell K1.


Private Sub CommandButton6_Click()
If MsgBox("Are you sure?", vbYesNo) = vbNo Then
Exit Sub
End If
Dim c
Dim firstAddress As String, tmp As Integer
Dim tmp_array()

With Worksheets(2)
Set c = .Range("A1").CurrentRegion.Columns(1).Find
(TextBox1.Text, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
If c.Offset(0, 1).Value = TextBox2.Text And
c.Offset(0, 2).Value = TextBox3.Text Then
On Error GoTo err1
ReDim Preserve tmp_array(UBound(tmp_array)
+ 1)
On Error GoTo 0
tmp_array(UBound(tmp_array)) = c.Address
(False, False)
End If
Set c = .Range("A1").CurrentRegion.Columns
(1).FindNext(c)
Loop While Not c Is Nothing And c.Address <
firstAddress
On Error GoTo err2
For tmp = UBound(tmp_array) To 1 Step -1
.Range(tmp_array(tmp)).EntireRow.Delete
Next
End If
End With
Unload Me
MsgBox "1 Record Deleted Successfully", vbOKOnly

err2:
Exit Sub

err1:
ReDim tmp_array(1)
Resume Next
End Sub




Thanx,
Todd



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 237
Default Modifying Code that deletes a Row

Thank you

Todd
-----Original Message-----
Todd,

This code

For tmp = UBound(tmp_array) To 1 Step -1
.Range(tmp_array(tmp)).EntireRow.Delete
Next

can be replaced by

For tmp = UBound(tmp_array) To 1 Step -1
Range("K1") = .Range(tmp_array(tmp)).Row
Next

but it will get over-written if you find more than 1

occurence.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Todd Huttenstine"

wrote in message
...
Hey guys

Happy Thanksgiving.

Here is a code(see below) that deletes the entire row if
Textbox1,2,and3 match data found in a row in range A1:A3
starting in A1.

What would the code be, that would put the number of the
row to be deleted in cell K1, instead of actually

deleting
the entire Row that matches the criteria in the 3
textboxes? I dont want to delete the row, just put the
row to be deleted in cell K1.


Private Sub CommandButton6_Click()
If MsgBox("Are you sure?", vbYesNo) = vbNo Then
Exit Sub
End If
Dim c
Dim firstAddress As String, tmp As Integer
Dim tmp_array()

With Worksheets(2)
Set c = .Range("A1").CurrentRegion.Columns(1).Find
(TextBox1.Text, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
If c.Offset(0, 1).Value = TextBox2.Text And
c.Offset(0, 2).Value = TextBox3.Text Then
On Error GoTo err1
ReDim Preserve tmp_array(UBound

(tmp_array)
+ 1)
On Error GoTo 0
tmp_array(UBound(tmp_array)) = c.Address
(False, False)
End If
Set c = .Range("A1").CurrentRegion.Columns
(1).FindNext(c)
Loop While Not c Is Nothing And c.Address <
firstAddress
On Error GoTo err2
For tmp = UBound(tmp_array) To 1 Step -1
.Range(tmp_array(tmp)).EntireRow.Delete
Next
End If
End With
Unload Me
MsgBox "1 Record Deleted Successfully", vbOKOnly

err2:
Exit Sub

err1:
ReDim tmp_array(1)
Resume Next
End Sub




Thanx,
Todd



.

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
Combination of / and 8 deletes the column [email protected] Excel Worksheet Functions 5 October 16th 08 07:40 PM
Keystroke that Deletes Entire Row? DeniseS Excel Discussion (Misc queries) 3 June 11th 07 04:46 PM
Macro that deletes every third row....+ ajjag Excel Discussion (Misc queries) 4 June 27th 06 06:03 PM
Detecting when a user deletes a row Wescotte Excel Worksheet Functions 0 November 8th 05 12:01 AM
Repetative Row Deletes scratching my head Excel Discussion (Misc queries) 1 May 30th 05 09:38 PM


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