It's pretty hard to give a good example involving the more complicated code.
I've tried but I always seem to come to a point where I just don't know what cells are being referred to on which sheet.
Here's a very simple example.
Sub Macro11_Prep_Rents()
With Sheets("MEMBERSHIP BOOK")
.Range("AL8:AL600").ClearContents
.Range("AN8:AN600").ClearContents
.Range("AP8:AP600").ClearContents
.Range("AR8:AR600").ClearContents
.Range("AT8:AT600").ClearContents
.Range("AV8:AV600").ClearContents
.Range("B5").Value = 366
End With
End Sub
Here's one of the subs I had trouble with.
'Copy All New & Current Members (Blakes)
'From Rents
'To Rents_Blakes
Sub Macro03_Update_Blakes_Rents()
Dim Ws1 As Worksheet, Ws2 As Worksheet, lastA As Long, i As Integer
Set Ws1 = Sheets("RENTS")
Set Ws2 = Sheets("RENTS_BLAKES")
Application.ScreenUpdating = False
Ws2.Select
Range("A8:AZ600").Select
Application.CutCopyMode = False
Selection.ClearContents
Range("A1").Select
With Ws1
For i = 8 To 600
If UCase(.Range("J" & i).Value) = "BLAKE'S" Then
If Ws2.Range("A600").End(xlUp).Row < 8 Then
lastA = 7
Else
lastA = Ws2.Range("A600").End(xlUp).Row
End If
.Rows(i).EntireRow.Copy Destination:=Ws2.Rows(lastA + 1)
Application.CutCopyMode = False
End If
Next
End With
Range("A8").Select
Range("A8:AZ75").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A8:AZ" & Range("B65536").End(xlUp).Row).Sort Key1:=Range("J8"), _
Order1:=xlAscending, Key2:=Range("A8"), _
Order2:=xlAscending, Header:=xlNo
Set Ws1 = Nothing
Set Ws2 = Nothing
Application.ScreenUpdating = True
End Sub
The first part is easy to deal with.
Ws2.Range("A8:AZ600").ClearContents
The With End With after that part is fine, everything referenced correctly.
It's this part that's the problem.
Range("A8").Select
Range("A8:AZ75").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A8:AZ" & Range("B65536").End(xlUp).Row).Sort Key1:=Range("J8"), _
Order1:=xlAscending, Key2:=Range("A8"), _
Order2:=xlAscending, Header:=xlNo
It's easy to get rid of the Selects, but which worksheet is A8:AZ75 on? Is it Ws1 or Ws2?
With Range("A8:AZ75")
.Copy
.PasteSpecial Paste:=xlPasteValues
End With
Bookmarks