Dear All,
Currently I am having problems with my macro as it fails to capture visible cells as array values.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
If I use myVRng.address then I get B528:B554, B728:B1053, B2123:B2500 but really B528:B524 and B738:B1053.<o></o>
It only captures first lot as 27 cells (B528:B554).<o></o>
I believe problem is because NonContiguous range.<o></o>
<o> </o>
Is there a way to fix this problem?
<o>
</o>
Any help would greatly appreciated?
Biz
Currently I am having problems with my macro as it fails to capture visible cells as array values.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
If I use myVRng.address then I get B528:B554, B728:B1053, B2123:B2500 but really B528:B524 and B738:B1053.<o></o>
It only captures first lot as 27 cells (B528:B554).<o></o>
I believe problem is because NonContiguous range.<o></o>
<o> </o>
Is there a way to fix this problem?
<o>
Code:
Option Explicit
Option Base 1
Option Compare Text</o:p>[/SIZE][/FONT][/COLOR]
[COLOR=black][FONT=Calibri][SIZE=3]<o:p>Dim ws As Worksheet</o:p>[/SIZE][/FONT][/COLOR]
[COLOR=black][FONT=Calibri][SIZE=3]<o:p>Sub Main()
Dim rCells As Range, jRange As Range, tRange As Range, myVRng As Range
Dim jLR As Long, tLR As Long
Dim myarray As Variant, aCell As Variant, aStartTime
Dim i As Integer</o:p>[/SIZE][/FONT][/COLOR]
[COLOR=black][FONT=Calibri][SIZE=3]<o:p>'Speeding Up VBA Code
Application.ScreenUpdating = False 'Prevent screen flickering
Application.Calculation = xlCalculationManual 'Preventing calculation
Application.DisplayAlerts = False 'Turn OFF alerts
Application.EnableEvents = False 'Prevent All Events</o:p>[/SIZE][/FONT][/COLOR]
[COLOR=black][FONT=Calibri][SIZE=3]<o:p>'Start Timer
aStartTime = Now()
Call uUnProtect</o:p>[/SIZE][/FONT][/COLOR]
[COLOR=black][FONT=Calibri][SIZE=3]<o:p>'Removes AutoFilter if one exists
Worksheets("JobCodes").AutoFilterMode = False
'Add AutoFilter with a criteria
Worksheets("JobCodes").ListObjects("Table_KILO_FinTool_l_Job").Range.AutoFilter Field:=2 _
, Criteria1:=Array("38130", "38145", "38150", "38155", "38160", "38165", "38170", "38175", "38180", "38185"), Operator:=xlFilterValues
'<<<====Change Required</o:p>[/SIZE][/FONT][/COLOR]
[COLOR=black][FONT=Calibri][SIZE=3]<o:p>
jLR = Range("aaTopJR").Parent.Cells(Rows.Count, Range("aaTopJR").Column).End(xlUp).Row
tLR = Range("tTopJobNo").Parent.Cells(Rows.Count, Range("tTopJobNo").Column).End(xlUp).Row
Set jRange = Sheets("JobCodes").Range("B2:B" & jLR)
Set tRange = Sheets("Input").Range("B7:B" & tLR)
'Derived Visible Range from Jobcodes Tab
With Worksheets("JobCodes")
With .AutoFilter.Range
If .Columns(3).Cells.SpecialCells(xlCellTypeVisible).Cells.Count = 1 Then
'do nothing, only the header is visible
Else
'go to column 3 (C) and come down a row and subtract a row to ignore the header
'Rows.count-1 to get last visible cell with data
'Offset (1,-2) to go back to column B
Set myVRng = .Columns(3).Resize(.Rows.Count - 1, 1).Offset(1, -2) _
.Cells.SpecialCells(xlCellTypeVisible)
End If
End With
End With
'Process Ranges using Arrays
myarray = myVRng.Value
'Looping structure to look at array.
For i = 1 To UBound(myarray)
'MsgBox myarray(i, 1)
aCell = Application.VLookup(myarray(i, 1), tRange, 1, 0)
If IsError(aCell) Then
If IsEmpty(Range("B7")) Then
Sheets("Input").Cells(65536, Range("B7").Column).End(xlUp).Value = myarray(i, 1) 'if only values are needed: Destination.value=Target.value
Else
Sheets("Input").Cells(65536, Range("B6").Column).End(xlUp).Offset(1, 0).Value = myarray(i, 1) 'if only values are needed: Destination.value=Target.value
End If
End If
Next i
'Speeding Up VBA Code
Application.ScreenUpdating = True 'Prevent screen flickering
Application.Calculation = xlAutomatic 'Preventing calculation
Application.DisplayAlerts = True 'Turn OFF alerts
Application.EnableEvents = True 'Prevent All Events
Call uProtect
'Release memory
Set jRange = Nothing
Set tRange = Nothing
'End Timer
MsgBox "Time taken: " & Format(Now() - aStartTime, "h:mm:ss"), vbInformation, "Complete"
End Sub
Any help would greatly appreciated?
Biz