Instead of multiple Ifs, use Select Case, it's easier to follow.
Instead of multiple Ifs, use Select Case, it's easier to follow.
Hope that helps.
RoyUK
--------
For Excel Tips & Solutions, free examples and tutorials why not check out my web site
Free DataBaseForm example
I still need to look up how to use CASE properly,
but besides that, this is something I was trying to do. Of course it does not work yet? Suggestions??
Here's how your case should look, but I don't understand what you mean by "for each selection" ... each selection of what?
![]()
Select Case Range("N5") Case 1 To 5 Set Ws = Worksheets("Sheet2") Case 2, 8, 14 Set Rng2 = Range("C36:C41") End Select Select Case Range("Q5").Value Case 1 Set Rng1 = Range("C28:C33") End Select
MatrixMan.
--------------------------------------
If this - or any - reply helps you, remember to say thanks by clicking on *Add Reputation.
If your issue is now resolved, remember to mark as solved - click Thread Tools at top right of thread.
Not sure if this is what you want, sheet references might need changing, but I have attempted to change your code to use Select Case
![]()
Sub AutoShape1_Click() With Application .ScreenUpdating = False Dim Ws As Worksheet Dim Rng1 As Range Dim Rng2 As Range Select Case Range("N5").Value Case 1 To 5: Set Ws = Worksheet("Sheet2") Case 2, 8, 14: Set Rng2 = Range("C36:C41") Case Else: MsgBox "Incorrect entry" End Select Select Case Range("Q5").Value Case 1: Set Rng1 = Range("C28:C33") Case Else: MsgBox "Incorrect entry" End Select 'The next part would do the copying and pasting depending upon what I selected Rng1.Copy Destination:=Rng2 .ScreenUpdating = False .CutCopyMode = False End With End Sub
I think we are close.
the one line
gives me an errorHTML Code:
if I do this:
It works with assigning a value to the rng2HTML Code:
Versus:![]()
Rng1.Copy Destination:=Ws.Range("C28:C33")
The 2nd one should be![]()
Rng1.Copy Destination:=Rng2
... so it goes to the right sheet, otherwise you're cutting & pasting to the same place in the active sheet ..![]()
Rng1.Copy Destination:=Ws.Rng2
Or - since you've got different variables for the same range address (as far as I can tell from the snippet) then set Rng2 explicitly such as:
And then you can:![]()
Set Rng2=Ws.Range("C28:C33")
Hope that helps![]()
Rng1.Copy Destination:=Rng2
![]()
When I do change to this:
I get the error: Method or data member not found. Is it assinged or DIm correctly??HTML Code:
I also thought that would work.
I was looking for more examples as how to fix my macro but I am still in need of more expertise.
I attached my last go around. I did manage to change another macro by using variables. Yeally shortens the code alot! So I am learning.
I have simplified this, it shoulod give you an idea what you need to do.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks