Hi all,
I have a macro which executes various subs in order. I'm having trouble with one part of it. Essentially I need some code which produces what is shown in the example worksheet.
Any ideas?
Hi all,
I have a macro which executes various subs in order. I'm having trouble with one part of it. Essentially I need some code which produces what is shown in the example worksheet.
Any ideas?
Last edited by D_N_L; 03-07-2012 at 06:44 AM.
So what you want is to delete the "#¡REF!"?
Try this code in a blank module -Option Explicit Dim lrow As Long Dim lrow1 As Long Dim i As Long Sub clear_data() With Worksheets("DataPrep") lrow = .Range("A" & .Rows.Count).End(xlUp).Row lrow1 = .Range("B" & .Rows.Count).End(xlUp).Row If lrow1 > lrow Then lrow = lrow1 End If For i = 2 To lrow If Application.IsError(.Range("A" & i).Value) = True And Application.IsError(.Range("B" & i).Value) = False Then .Range("A" & i).Value = "" ElseIf Application.IsError(.Range("A" & i).Value) = False And Application.IsError(.Range("B" & i).Value) = True Then .Range("B" & i).Value = "" ElseIf Application.IsError(.Range("A" & i).Value) = True And Application.IsError(.Range("B" & i).Value) = True Then .Range("A" & i).Value = "" .Range("B" & i).Value = "" End If Next i ActiveWorkbook.Worksheets("DataPrep").Sort.SortFields.Clear ActiveWorkbook.Worksheets("DataPrep").Sort.SortFields.Add Key:=Range("A:A") _ , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal With ActiveWorkbook.Worksheets("DataPrep").Sort .SetRange Range("A:A") .Header = xlYes .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With ActiveWorkbook.Worksheets("DataPrep").Sort.SortFields.Clear ActiveWorkbook.Worksheets("DataPrep").Sort.SortFields.Add Key:=Range("B:B") _ , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal With ActiveWorkbook.Worksheets("DataPrep").Sort .SetRange Range("B:B") .Header = xlYes .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With End With End Sub
If I have helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
Thanks Arlette! Works like a charm!
(Sorry Pichingualas - Yes that is what I meant).
Thank you very much for you time.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks