Problem with a Messy With .range statement

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have this code in which the line in red is giving me an error ("Wrong number of arguments or invalid property assignment")
rwend = 27

Rich (BB code):
Sub process_surfaceconditions()
    Application.EnableEvents = False
    Application.ScreenUpdating = False
    With ws_form
        .Unprotect
        With .Range("E" & rwend + 3 & ":E" & rwend + 8, "E" & rwend + 10 & ":E" & rwend + 11, "K" & rwend + 3 & ":K" & rwend + 8, "K" & rwend + 10 & ":K" & rwend + 11, "M" & rwend + 1)
            .Value = ""
            .Interior.ColorIndex = xlNone
        End With
        .Protect
    End With
        Application.EnableEvents = False
    Application.ScreenUpdating = False
End Sub

It's such a messy line, that whatever the problem is I feel it's very subtle and hard to spot. Can somewhat spot the error? Is there a cleaner way of writing that same line possibly?
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try this line instead. The commas between the ranges must be part of the string representing the cell addresses. Your original code would reference (depending on rwend's value) something like: Range("E1:E10", "E15:E20", ...)
When it should be like: Range("E1:E10,E15:E20,...")
VBA Code:
With .Range("E" & rwend + 3 & ":E" & rwend + 8 & ", E" & rwend + 10 & ":E" & rwend + 11 & ", K" & rwend + 3 & ":K" & rwend + 8 & ", K" & rwend + 10 & ":K" & rwend + 11 & ", M" & rwend + 1)
I assume "ws_form" is also assigned as a worksheet elsewhere in your code.
 
Upvote 0
Solution
Ah, ok. I see the logic there helping to explain where I went wrong. Thank you for the explanation and the solution Z51!
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,822
Members
449,469
Latest member
Kingwi11y

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top