Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Editing Code - Help!!!

Hi...

The code below launches an input box then deletes any row
in which the value entered into the input box is found. I
can't work out how I edit this code so the value entered
into the input box will copy all rows of its occourance
into a new worksheet within the workbook rather than
delete it.

Any help would be appreciated.

Public Sub remove()
Worksheets("Sheet1").Activate
Dim lastrow As Long
Dim lastcol As Long
Dim sString As String
sString = InputBox("ENTER YOUR VALUE: ANY ROW ON
WHICH THIS VALUE IS FOUND WILL BE DELETED")
If sString = "" Then
MsgBox "No search criteria requested.", vbOKOnly +
vbInformation, "Cancel is pressed."
Exit Sub
End If

lastrow = ActiveSheet.UsedRange.Rows.Count
lastcol = ActiveSheet.UsedRange.Columns.Count
Application.ScreenUpdating = False
Dim ir As Long, ic As Long, rd As Long
For ir = lastrow To 1 Step -1
For ic = lastcol To 1 Step -1
Cells(ir, ic).Activate
If UCase(Cells(ir, ic).Value) = UCase(sString) Then
Rows(ir).Delete Shift:=xlUp
ir = ir - 1
ic = lastcol + 1
rd = rd + 1
End If
Next ic
Next ir
Application.ScreenUpdating = True
MsgBox "You have deleted: " & rd & " rows"
End Sub

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default Editing Code - Help!!!

Hi,
Try adding a line of code just before the delete line
Rows(ir).copy destination:= sheets(your new
sheet).Range("A1").end(xldown).offset(1,0)

-----Original Message-----
Hi...

The code below launches an input box then deletes any row
in which the value entered into the input box is found. I
can't work out how I edit this code so the value entered
into the input box will copy all rows of its occourance
into a new worksheet within the workbook rather than
delete it.

Any help would be appreciated.

Public Sub remove()
Worksheets("Sheet1").Activate
Dim lastrow As Long
Dim lastcol As Long
Dim sString As String
sString = InputBox("ENTER YOUR VALUE: ANY ROW ON
WHICH THIS VALUE IS FOUND WILL BE DELETED")
If sString = "" Then
MsgBox "No search criteria requested.", vbOKOnly +
vbInformation, "Cancel is pressed."
Exit Sub
End If

lastrow = ActiveSheet.UsedRange.Rows.Count
lastcol = ActiveSheet.UsedRange.Columns.Count
Application.ScreenUpdating = False
Dim ir As Long, ic As Long, rd As Long
For ir = lastrow To 1 Step -1
For ic = lastcol To 1 Step -1
Cells(ir, ic).Activate
If UCase(Cells(ir, ic).Value) = UCase(sString) Then
Rows(ir).Delete Shift:=xlUp
ir = ir - 1
ic = lastcol + 1
rd = rd + 1
End If
Next ic
Next ir
Application.ScreenUpdating = True
MsgBox "You have deleted: " & rd & " rows"
End Sub

Thanks
.

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
Need help editing this code James Excel Discussion (Misc queries) 8 September 19th 08 05:18 PM
editing code in modules through VB mark Excel Programming 2 August 12th 04 05:20 PM
Editing code Todd Huttenswtine Excel Programming 3 December 29th 03 06:18 AM
Recalculation Speed After Editing Macro Code Bob Keating Excel Programming 1 November 16th 03 01:08 PM
Protect macro code from viewing/editing Keith[_8_] Excel Programming 5 October 30th 03 02:59 PM


All times are GMT +1. The time now is 10:31 AM.

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"