PDA

View Full Version : [SOLVED:] Range instead of fixed value



Kilroy
09-12-2017, 07:09 AM
Guys I have been working with this code I believe was written by Greg. It works perfectly but I can't figure out how to have a range for "Find Text". Right now it is set at "0" but most times I need a range of "0 - 10". Anyone able to point me in the right direction? Thanks

gmaxey
09-12-2017, 07:24 AM
What code was written by Greg?

Kilroy
09-12-2017, 08:00 AM
LOL I guess it helps to include the code. I need to be able to select different ranges. 0, 0-1 up to 0-10.


Sub DeleteIfZeroCell4()
Dim oTbl As Table
Dim lngIndex As Long, lngCell As Long
Dim bKill As Boolean
Set oTbl = Selection.Tables(1)
For lngIndex = oTbl.Rows.Count To 2 Step -1
bKill = True
For lngCell = 4 To 4
If Left(oTbl.Cell(lngIndex, lngCell).range.Text, 1) <> "0" Then
bKill = False
Exit For
End If
If bKill Then oTbl.Rows(lngIndex).Delete
Next lngCell
Next lngIndex
lbl_Exit:
Exit Sub
End Sub

gmaxey
09-12-2017, 08:30 AM
I really don't know what you are trying to do, but you might try using Like e.g., Like [0-1] or Like [0-10]

Kilroy
09-12-2017, 08:50 AM
I have a table that has been through some processing that populates column 4 with numbers. I need to be able to delete the rows with certain values. In the example below there are values from 0-5. I would like to be able to set the rows to delete by giving a range like 1-3, or maybe 0 or 1-4.





For implementation effectiveness quality assurance program site.



5





To interface Industrial quality personnel matters relating quality.



4





To interface Customers Quality Surveillance personnel matters related quality.



3



3.6.26

DIRECTOR QUALITY; position reports president shall responsible overall management Quality Assurance.



2



3.6.27

SENIOR QUALITY MANAGER; position reports Director Quality shall responsible



1



1.0

Organizational Structure



0

gmaxey
09-13-2017, 05:54 AM
Option Explicit
Sub DeleteIfZeroCell4()
Dim oTbl As Table
Dim lngIndex As Long, lngCell As Long
Dim strRange ' As String
Set oTbl = Selection.Tables(1)
strRange = "[" & InputBox("Enter value range, e.g.,:", "Range", "1-3,5-7,9") & "]"
For lngIndex = oTbl.Rows.Count To 2 Step -1
Select Case True
Case fcnCellText(oTbl.Cell(lngIndex, 4)) Like strRange
oTbl.Rows(lngIndex).Delete
End Select
Next lngIndex
lbl_Exit:
Exit Sub
End Sub
Function fcnCellText(oCell As Cell) As String
fcnCellText = Left(oCell.Range.Text, Len(oCell.Range.Text) - 2)
lbl_Exit:
Exit Function
End Function

Kilroy
09-13-2017, 09:34 AM
Thanks Greg works perfect!