Hi,
Can anyone help to amend this code? I need the code to add a zero in columns B&C in range if I in sheet 2 is not available.
Sub Burt_100()
Dim Sh1 As Worksheet
Dim Sh2 As Worksheet
Dim i As Integer
Dim Col_B As String
Dim Col_C As String
Dim column As String
Dim Lastrow As Integer
Dim value As Integer
Application.ScreenUpdating = False
Set Sh1 = ThisWorkbook.Sheets(1)
Set Sh2 = ThisWorkbook.Sheets(2)
'activating sheets is not really necessary and it's really dangerous
'to rely on the active sheet to define steps in your code...
'i left the activate lines in here so you can see your stuff but
'i added Sh1 or Sh2 in several places to help keep it all straight
Sh1.Activate
'your comments make it sound like .select somehow worked here but i
'don't understand how that would be the case - i used .row to get it
'to work for me
Lastrow = Sh1.Range("B6").End(xlDown)(2, 1).Row
Sh2.Activate
For i = 1 To Sh2.Range("A:A").End(xlDown).Offset(1, 0).Row
If Trim(Sh2.Cells(i, 1)) = "I" Then
Col_B = Sh2.Cells(i, 2)
Col_C = Sh2.Cells(i, 3)
Sh1.Activate
'again your comments make it sound like cells(Lastrow) was working
'but i got an error every time i tried to run anything so i switched
'these lines to cells(Lastrow, 2) and cells(Lastrow, 3)
Cells(Lastrow, 2) = Col_B
Cells(Lastrow, 3) = Col_C
If Cells(Lastrow + 1, 2) = "" Then
Lastrow = Lastrow + 1
Else
Lastrow = Lastrow + 2
End If
Col_B = vbNullString
Col_C = vbNullString
End If
Next i
Sh1.Activate
Application.ScreenUpdating = True
End Sub
Thanks
Johnny
Bookmarks