hi!
Would it it be possible to examine my code and comment some errors that as a newcomer I missed?
The code should extract from sheet1 the rows that have a certain value on column 6. First I have to extract the value of reference, which is the max value on this column. Problem is that it is formatted as text so I try to format it as value first, and then extract the max value. Each entry of this column is then compared to this value of reference and the matching ones are extracted to sheet 3.
THanks for any comments
code:
Sub Find()
Dim dat As Integer, datold As Integer, x As Integer
Dim lRow As Long, lcol As Integer, i As Integer, refArr As Variant, CompArr As Variant
Dim refSht As Worksheet, compSht As Worksheet, incr As Long
Set refSht = Sheets("Sheet1"
Set compSht = Sheets("sheet2"
lRow = refSht.UsedRange.Rows.Count
lcol = refSht.UsedRange.Columns.Count
refSht.Select
'below is to format text data to numbers
refSht.Range("ff1"
= 1
refSht.Range("FF1"
.Select
Selection.Copy
Columns("F:F"
.Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply, _
SkipBlanks:=False, Transpose:=False
'put the max value into reference
dat = Application.WorksheetFunction.Max(Range("f:f"
)
Range("ff1"
= ""
datold = dat - 7
refArr = refSht.Range(Cells(1, 6), Cells(lRow, 6))
For x = LBound(refArr) To UBound(refArr)
incr = 1
If refArr(x, 1) > datold Then
refSht.Range(Range(Cells(x, 1), Cells(x, lcol)).Address).Copy Destination:=Sheets("Sheet3"
.Range("A" & incr)
incr = incr + 1
End If
Next x
GetDiffs
End Sub
Would it it be possible to examine my code and comment some errors that as a newcomer I missed?
The code should extract from sheet1 the rows that have a certain value on column 6. First I have to extract the value of reference, which is the max value on this column. Problem is that it is formatted as text so I try to format it as value first, and then extract the max value. Each entry of this column is then compared to this value of reference and the matching ones are extracted to sheet 3.
THanks for any comments
code:
Sub Find()
Dim dat As Integer, datold As Integer, x As Integer
Dim lRow As Long, lcol As Integer, i As Integer, refArr As Variant, CompArr As Variant
Dim refSht As Worksheet, compSht As Worksheet, incr As Long
Set refSht = Sheets("Sheet1"
Set compSht = Sheets("sheet2"
lRow = refSht.UsedRange.Rows.Count
lcol = refSht.UsedRange.Columns.Count
refSht.Select
'below is to format text data to numbers
refSht.Range("ff1"
refSht.Range("FF1"
Selection.Copy
Columns("F:F"
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply, _
SkipBlanks:=False, Transpose:=False
'put the max value into reference
dat = Application.WorksheetFunction.Max(Range("f:f"
Range("ff1"
datold = dat - 7
refArr = refSht.Range(Cells(1, 6), Cells(lRow, 6))
For x = LBound(refArr) To UBound(refArr)
incr = 1
If refArr(x, 1) > datold Then
refSht.Range(Range(Cells(x, 1), Cells(x, lcol)).Address).Copy Destination:=Sheets("Sheet3"
incr = incr + 1
End If
Next x
GetDiffs
End Sub