Ok, first things first, get out of the habit of selecting and activating. Reference objects directly. Besides issues arising from not selecting the right object, it takes less code and executes quicker.
Sub SelectingPartOfTable()
Dim wbErrorLog as Workbook
Dim wsErrorLog as Worksheet
Dim wsRisk as Worksheet
Dim i as Integer
Set wbErrorLog = Workbooks.Open Filename:="Y:\Guinness\Error Log\NBCGF Event Log.xlsm"
Set wsErrorLog = wbErrorLog.Sheets("NBCGF Error Log")
Set wsRisk = Workbooks("Risk").Sheets("Sheet1")
For i = 1 To 100
If wsRisk.Range("b" & i) = Now() Then
wsRisk.Range("b" & i).EntireRow.Copy
with wsErrorLog.Range("a2").EntireRow
.Insert Shift:=xlDown
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
Next
End Sub
This will result in each new line found in the Risk sheet being inserted into row 2 of the ErrorLog and each previously found line being shifted down to make way for it.
You could also write it so that each new line gets added to the NEXT line of the ErrorLog:
Sub SelectingPartOfTable()
Dim wbErrorLog as Workbook
Dim wsErrorLog as Worksheet
Dim wsRisk as Worksheet
Dim i as Integer
Dim WriteLine as Integer
Set wbErrorLog = Workbooks.Open Filename:="Y:\Guinness\Error Log\NBCGF Event Log.xlsm"
Set wsErrorLog = wbErrorLog.Sheets("NBCGF Error Log")
Set wsRisk = Workbooks("Risk").Sheets("Sheet1")
WriteLine = 2
For i = 1 To 100
If wsRisk.Range("b" & i) = Now() Then
wsRisk.Range("b" & i).EntireRow.Copy
with wsErrorLog.Range("a" & WriteLine).EntireRow
.PasteSpecial xlPasteAll
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
WriteLine = WriteLine + 1
End If
Next
End Sub
Hope this helps.
Bookmarks