Help needed - The command cannot be used on multiple selections

Novelec

Board Regular
Joined
Nov 3, 2012
Messages
85
Hi forum,

Put your reading glasses on!

I've somehow run into the error "The command cannot be used on multiple selections"...

After doing some research, I understand this error relates to a range being an odd shape, and excel not knowing how to handle it during a copy-paste function? I'm sure the range I am trying to copy-paste is a standard rectangle, so I don't know why I'm getting this error. My VBA skillset is underdeveloped to say the least (non-existent would be more accurate), so please excuse my lack of, and incorrect use of terminology from here on.

I've created a series of check sheets, and now I'm trying to create an automated summary of these using VBA. There are five check sheets, and one summary sheet (6 separate worksheets, all in the one workbook) in total. Each check sheet is made up of one column listing checks to complete, two columns representing Marlett check boxes (for checking a 'pass' or 'fail'), and one column to list any comments associated with each check.

I've created named ranges out of all of the fail check boxes as they belong to different categories, and as such are not continuous (and they are what I want in the summary). Using VBA I've consolidated all of the named ranges on each individual sheet to form a "union-ed range" of fail checks for each respective sheet. The code then goes on to assess each cell in each "union-ed range" to see if it contains the text "a" (this a represents a "fail" marlett check box that has been ticked).

After finding a failed check, a nested "do while" loop first assesses each cell in the "fail" marlett checkbox column. It does this specifically in an upwards direction, so as to find the cell containing the title which relates to the failed check. It then repeats this process a second time (second part of "do while nest") to find another title further up the page. Both titles are located according to their unique cell fill colour.

Once the failed check has been located, along with its two associated titles, the code adds all three results to a range (at this point I will note that all three results are always of the same horizontal cell dimension, column location, and do not contain any merged cells). This range is then built on via the union function, as the code goes through and assesses the rest of the "union-ed" range of fail checks.

So........ This is where things have been a bit shaky. Once the code has checked the whole worksheet, the range containing all of the failed checks with their associated titles is copy-pasted to a specific location on the summary worksheet. Prior to pasting, a value is returned to nominate how many rows will need to be inserted on the summary sheet to fit the "results range". Up to here I've had this working (believe it or not!).

This portion of code is where my error emerges from - "The command cannot be used on multiple selections". The debugger highlights the copy-paste line of code at the very end (highlighted in red). I've removed the code that adds the to the "results range" (highlighted in orange), and substituted it for messages boxes (highlighted in green) to display the cell address of each result. This was to confirm that the code was in fact retrieving the expected cell addresses, in the correct order. Surprisingly it was.

Leaving the code in the same order, and simply enabling/disabling a line at a time I did some fault finding. If the code pastes only "title a" to the summary sheet, it works, and even pastes the correct results! I can even have the code paste the failed check, as well as "title a" or "title b", and it does this correctly too! But when I put all three together, the fun stops...

I apologise for the long winded explanation, I just wanted to make sure the whole process was understood. I also apologise for the scattered code layout - I've mentioned in previous threads that my knowledge extends no further than that of a copy-paste soldier. So it goes without saying I don't follow any protocol as such. I'm amazed I've made it this far to be honest...

I've received so much help from people here at MrExcel, I can't thank the community here enough! :-) As always, I'm very grateful for any assistance on this thread.

Cheers,

Dan

Code:
    Set Basement_Range = Union(Range("Lots_of_named_ranges..."), Range("etc1"), Range("etc2"), Range("etc3"))
     
    For Each Cell In Basement_Range
        If Cell.Text = "a" Then
            i = Cell.Row
            Do Until i = 1
                If Sheets("Basement").Range("I" & i).Interior.Color = RGB(79, 129, 189) Then
[COLOR=#ff8c00]                    If Basement_No_Checks Is Nothing Then
                        Set Basement_No_Checks =  Range(Sheets("Basement").Range("I" & i).Offset(-1, -8),  Sheets("Basement").Range("I" & i).Offset(0, 12))
                    Else
                        Set Basement_No_Checks =  Union(Basement_No_Checks, Range(Sheets("Basement").Range("I" &  i).Offset(-1, -8), Sheets("Basement").Range("I" & i).Offset(0, 12)))
                    End If[/COLOR]
                        j = Cell.Row
                        Do Until j = 1
                            If Sheets("Basement").Range("I" & j).Interior.Color = RGB(220, 230, 241) Then
[COLOR=#ff8c00]                               Set Basement_No_Checks =  Union(Basement_No_Checks, Range(Sheets("Basement").Range("I" &  j).Offset(-2, -8), Sheets("Basement").Range("I" & j).Offset(0, 12)))
[/COLOR]                                [COLOR=#ff8c00]Set Basement_No_Checks = Union(Basement_No_Checks, Range(Cell.Offset(0, -8), Cell.Offset(0, 12)))[/COLOR]
                        
[COLOR=#008000]'        MsgBox "Found section title at address: " & Sheets("Basement").Range("I" & i).Address
'        MsgBox "Found ROOM title at address: " & Sheets("Basement").Range("I" & j).Address[/COLOR]
        
                        Exit Do
                            End If
                        j = j - 1
                        Loop
            Exit Do
                End If
            i = i - 1
            Loop
        End If
        
    Next

    If Basement_No_Checks Is Nothing Then
        MsgBox "There are no failed checks in the Basement"
    ElseIf (ActiveWorkbook.Sheets("Summary").Range("Summary_Basement").Offset(3, 0)) = "" Then
        Number_of_Basement_Rows = ((Basement_No_Checks.Count) \ 20)
        Application.Goto (ActiveWorkbook.Sheets("Summary").Range("Summary_Basement").Offset(3, 0))
        ActiveCell.Resize(Number_of_Basement_Rows).EntireRow.Insert
[COLOR=#ff0000]        Basement_No_Checks.Copy Destination:=(ActiveWorkbook.Sheets("Summary").Range("Summary_Basement").Offset(3, -1))[/COLOR]
    End If
 
Last edited:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi forum,

Put your reading glasses on!

I've somehow run into the error "The command cannot be used on multiple selections"...

After doing some research, I understand this error relates to a range being an odd shape, and excel not knowing how to handle it during a copy-paste function? I'm sure the range I am trying to copy-paste is a standard rectangle, so I don't know why I'm getting this error. My VBA skillset is underdeveloped to say the least (non-existent would be more accurate), so please excuse my lack of, and incorrect use of terminology from here on.

I've created a series of check sheets, and now I'm trying to create an automated summary of these using VBA. There are five check sheets, and one summary sheet (6 separate worksheets, all in the one workbook) in total. Each check sheet is made up of one column listing checks to complete, two columns representing Marlett check boxes (for checking a 'pass' or 'fail'), and one column to list any comments associated with each check.

I've created named ranges out of all of the fail check boxes as they belong to different categories, and as such are not continuous (and they are what I want in the summary). Using VBA I've consolidated all of the named ranges on each individual sheet to form a "union-ed range" of fail checks for each respective sheet. The code then goes on to assess each cell in each "union-ed range" to see if it contains the text "a" (this a represents a "fail" marlett check box that has been ticked).

After finding a failed check, a nested "do while" loop first assesses each cell in the "fail" marlett checkbox column. It does this specifically in an upwards direction, so as to find the cell containing the title which relates to the failed check. It then repeats this process a second time (second part of "do while nest") to find another title further up the page. Both titles are located according to their unique cell fill colour.

Once the failed check has been located, along with its two associated titles, the code adds all three results to a range (at this point I will note that all three results are always of the same horizontal cell dimension, column location, and do not contain any merged cells). This range is then built on via the union function, as the code goes through and assesses the rest of the "union-ed" range of fail checks.

So........ This is where things have been a bit shaky. Once the code has checked the whole worksheet, the range containing all of the failed checks with their associated titles is copy-pasted to a specific location on the summary worksheet. Prior to pasting, a value is returned to nominate how many rows will need to be inserted on the summary sheet to fit the "results range". Up to here I've had this working (believe it or not!).

This portion of code is where my error emerges from - "The command cannot be used on multiple selections". The debugger highlights the copy-paste line of code at the very end (highlighted in red). I've removed the code that adds the to the "results range" (highlighted in orange), and substituted it for messages boxes (highlighted in green) to display the cell address of each result. This was to confirm that the code was in fact retrieving the expected cell addresses, in the correct order. Surprisingly it was.

Leaving the code in the same order, and simply enabling/disabling a line at a time I did some fault finding. If the code pastes only "title a" to the summary sheet, it works, and even pastes the correct results! I can even have the code paste the failed check, as well as "title a" or "title b", and it does this correctly too! But when I put all three together, the fun stops...

I apologise for the long winded explanation, I just wanted to make sure the whole process was understood. I also apologise for the scattered code layout - I've mentioned in previous threads that my knowledge extends no further than that of a copy-paste soldier. So it goes without saying I don't follow any protocol as such. I'm amazed I've made it this far to be honest...

I've received so much help from people here at MrExcel, I can't thank the community here enough! :-) As always, I'm very grateful for any assistance on this thread.

Cheers,

Dan

Code:
    Set Basement_Range = Union(Range("Lots_of_named_ranges..."), Range("etc1"), Range("etc2"), Range("etc3"))
     
    For Each Cell In Basement_Range
        If Cell.Text = "a" Then
            i = Cell.Row
            Do Until i = 1
                If Sheets("Basement").Range("I" & i).Interior.Color = RGB(79, 129, 189) Then
[COLOR=#ff8c00]                  If Basement_No_Checks Is Nothing Then
                        Set Basement_No_Checks =  Range(Sheets("Basement").Range("I" & i).Offset(-1, -8),  Sheets("Basement").Range("I" & i).Offset(0, 12))
                    Else
                        Set Basement_No_Checks =  Union(Basement_No_Checks, Range(Sheets("Basement").Range("I" &  i).Offset(-1, -8), Sheets("Basement").Range("I" & i).Offset(0, 12)))
                    End If[/COLOR]
                        j = Cell.Row
                        Do Until j = 1
                            If Sheets("Basement").Range("I" & j).Interior.Color = RGB(220, 230, 241) Then
[COLOR=#ff8c00]                             Set Basement_No_Checks =  Union(Basement_No_Checks, Range(Sheets("Basement").Range("I" &  j).Offset(-2, -8), Sheets("Basement").Range("I" & j).Offset(0, 12)))
[/COLOR]                              [COLOR=#ff8c00]Set Basement_No_Checks = Union(Basement_No_Checks, Range(Cell.Offset(0, -8), Cell.Offset(0, 12)))[/COLOR]
                        
[COLOR=#008000]'        MsgBox "Found section title at address: " & Sheets("Basement").Range("I" & i).Address
'        MsgBox "Found ROOM title at address: " & Sheets("Basement").Range("I" & j).Address[/COLOR]
        
                        Exit Do
                            End If
                        j = j - 1
                        Loop
            Exit Do
                End If
            i = i - 1
            Loop
        End If
        
    Next

    If Basement_No_Checks Is Nothing Then
        MsgBox "There are no failed checks in the Basement"
    ElseIf (ActiveWorkbook.Sheets("Summary").Range("Summary_Basement").Offset(3, 0)) = "" Then
        Number_of_Basement_Rows = ((Basement_No_Checks.Count) \ 20)
        Application.Goto (ActiveWorkbook.Sheets("Summary").Range("Summary_Basement").Offset(3, 0))
        ActiveCell.Resize(Number_of_Basement_Rows).EntireRow.Insert
[COLOR=#ff0000]      Basement_No_Checks.Copy Destination:=(ActiveWorkbook.Sheets("Summary").Range("Summary_Basement").Offset(3, -1))[/COLOR]
    End If

Just guessing, Dan, that your first range in the Union is not in Sheets("Basement"), since the othrer ranges are specified as being in that sheet. If so, you would be limited in what you can do with the Basement_No_Checks variable. For instance, it will not copy because the underlying application cannot handle it.
 
Upvote 0
Just guessing, Dan, that your first range in the Union is not in Sheets("Basement"), since the othrer ranges are specified as being in that sheet. If so, you would be limited in what you can do with the Basement_No_Checks variable. For instance, it will not copy because the underlying application cannot handle it.

Hi JLGWhiz. Thanks for the suggestion. I'm afraid I don't know which range you are referring to though - There are a lot in there!

:confused:

Having said that, I can confirm that all of the data being analysed is on the same worksheet ("Basement"), and the only other worksheet that gets referenced is the "Summary" sheet for the copy-paste function.

Leaving the code in the same order, and simply enabling/disabling a line at a time I did some fault finding. If the code pastes only "title a" to the summary sheet, it works, and even pastes the correct results! I can even have the code paste the failed check, as well as "title a" or "title b", and it does this correctly too! But when I put all three together, the fun stops...

The fault finding process I've used has really confused me. I'm not sure why I can get each individual range to copy-paste on it's own, but can't get the whole lot to work together? I can even get one title to copy-paste with it's associated fail check, but it seems like the two titles are conflicting somehow... The two titles just won't copy-paste at the same time for some reason.

The code below (see code in green text) spits out a long series of message boxes with no errors raised, showing the results that are returned from the code. I've taken note of the results, and they are exactly what I had expected, in exactly the right order. As the results aren't added to a range, and subsequently are not copy-pasted, the code runs cleanly. I know I'm repeating myself now, but this is really well beyond my abilities, and I'm not sure how or where I should go about locating my errors...?

Code:
Set Basement_Range = Union(Range("Basement_Level_Fail_Marlett_Check_Boxes_Group_1"), Range("Basement_Level_Fail_Marlett_Check_Boxes_Group_2"), Range("Basement_Level_Fail_Marlett_Check_Boxes_Group_3"), Range("etc..."))
     
    For Each Cell In Basement_Range
        If Cell.Text = "a" Then
            i = Cell.Row
            Do Until i = 1
                If Sheets("Basement").Range("I" & i).Interior.Color = RGB(79, 129, 189) Then
                    If Basement_No_Checks Is Nothing Then
'                        Set Basement_No_Checks = Range(Sheets("Basement").Range("I" & i).Offset(-1, -8), Sheets("Basement").Range("I" & i).Offset(0, 12))
                    Else
'                       Set Basement_No_Checks = Union(Basement_No_Checks, Range(Sheets("Basement").Range("I" & i).Offset(-1, -8), Sheets("Basement").Range("I" & i).Offset(0, 12)))
                    End If
                        j = Cell.Row
                        Do Until j = 1
                            If Sheets("Basement").Range("I" & j).Interior.Color = RGB(220, 230, 241) Then
'                               Set Basement_No_Checks = Union(Basement_No_Checks, Range(Sheets("Basement").Range("I" & j).Offset(-2, -8), Sheets("Basement").Range("I" & j).Offset(0, 12)))
'                               Set Basement_No_Checks = Union(Basement_No_Checks, Range(Cell.Offset(0, -8), Cell.Offset(0, 12)))
                        
[COLOR=#008000]        MsgBox "Found SECTION title at address: " & Sheets("Basement").Range("I" & i).Address[/COLOR]
[COLOR=#008000]        MsgBox "Found ROOM title at address: " & Sheets("Basement").Range("I" & j).Address[/COLOR]
[COLOR=#008000]        MsgBox "Found FAILED CHECK at address: " & Cell.Address[/COLOR]
        
                        Exit Do
                            End If
                        j = j - 1
                        Loop
            Exit Do
                End If
            i = i - 1
            Loop
        End If
        
    Next
    
    If Basement_No_Checks Is Nothing Then
        MsgBox "There are no failed checks in the Basement"
    ElseIf (ActiveWorkbook.Sheets("Summary").Range("Summary_Basement").Offset(3, 0)) = "" Then
        Number_of_Basement_Rows = ((Basement_No_Checks.Count) \ 20)
        Application.Goto (ActiveWorkbook.Sheets("Summary").Range("Summary_Basement").Offset(3, 0))
        ActiveCell.Resize(Number_of_Basement_Rows).EntireRow.Insert
        Basement_No_Checks.Copy Destination:=(ActiveWorkbook.Sheets("Summary").Range("Summary_Basement").Offset(3, -1))
    End If
 
Last edited:
Upvote 0
Any other suggestions? Maybe the forums are empty because of the holiday season, and I'm one of the few suckers that got roped in to work...?

:stickouttounge:

In any case, I have a strange feeling that the two nested "Do Until" functions are the cause of my error. I of course, am too unskilled to understand why.

Any input would be great, cheers.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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