Need to loop missing out blank cells

mdos1

New Member
Joined
Jul 23, 2009
Messages
38
Hi,

i have a great macro that works well but, my lookup cells will now have a number of blank cells which i want the lookup to ignore. I have also just named the range of cell but don't know how to change it in the macro.

Any ideas?

Thanks Mark

Dim sIn As Worksheet
Dim sOut As Worksheet
Dim rIn As Integer
Dim cIn As Integer
Dim rOut As Integer
Dim cOut As Integer
Dim Num As Integer
Dim NewValue
Dim Found As Boolean
Dim SearchRange As Range

'set the two worksheets
Set sIn = Sheets("Schedule")
Set sOut = Sheets("Totals")

'start input from F19
rIn = 7

cIn = 6

'start output from A10
rOut = 24
cOut = 1
Num = 0

'clear ouput range
Range(sOut.Cells(rOut, cOut), sOut.Cells(rOut + 1000, cOut)).ClearContents

'this is needed for the Match function which returns an error if not found
On Error Resume Next

'run through input list
Do While sIn.Cells(rIn, cIn).Value <> ""
NewValue = sIn.Cells(rIn, cIn).Value

'try to find the item in the output list
Set SearchRange = Range(sOut.Cells(rOut, cOut), sOut.Cells(rOut + Num, cOut))

Found = False
Found = IsNumeric(Application.WorksheetFunction.Match(NewValue, SearchRange, 0))

'add item to destination
If Not Found Then
sOut.Cells(rOut + Num, cOut).Value = NewValue
Num = Num + 1
End If

rIn = rIn + 1
Loop

On Error GoTo 0

MsgBox "Completed processing. Unique items written:" + Str(Num)

' Sub SORT()
'
' SORT Macro
'
'
Range("A24:A252").Select
ActiveWorkbook.Worksheets("Totals").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Totals").Sort.SortFields.Add Key:=Range("A24:A42") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Totals").Sort
.SetRange Range("A24:A42")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,224,602
Messages
6,179,839
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top