Sort Columns low to high but im told cells are merged

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Hi,

I have two columns A & B of which i need each sorted separatley from low to high numbers.
This worked fine.
Rich (BB code):
Private Sub SortFrameNumbers_Click()
Range("A2:A150").Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlNo
Range("B2:B50").Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlNo
End Sub
It sorted column A from 1-100 perfect then it sorted column B 1-22 perfect.

So i then added it to my code which populates these two columns but i then get a RTE 1004 please see screenshot.

This is the code i added it to.

Rich (BB code):
Private Sub GoldWingCountry_Click()
    Dim Cell As Range
    Dim wsMC As Worksheet
    Dim wsCountry As Worksheet
    
    Set wsMC = Sheets("MCLIST")
    Set wsCountry = Sheets("COUNTRYLIST")
    
    With Sheets("COUNTRYLIST")
        .Range("A2:B1000").ClearContents
    End With
    
    wsCountry.Range("A1") = "GOLD WING UK"
    wsCountry.Range("B1") = "GOLD WING USA"
    
    With wsMC
        For Each Cell In .Range("D8:D" & .Cells(.Rows.Count, "D").End(xlUp).Row)
            If Cell.Value = "GOLD WING UK" Then
                wsCountry.Range("A" & Rows.Count).End(xlUp).Offset(1) = Cell.Offset(, -2)
            ElseIf Cell.Value = "GOLD WING USA" Then
               wsCountry.Range("B" & Rows.Count).End(xlUp).Offset(1) = Cell.Offset(, -2)
            End If
        Next Cell
    End With
    Sheets("COUNTRYLIST").Select
    Range("A2:A150").Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlNo
    Range("B2:B50").Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlNo
End Sub

I run the code & columns A & B are populated.

The code sorts column A2 & down the page from 1-100 etc & at this point column B is untouched.
Once done the code sorts column B2 & down the page from 1 -50 etc & at this point column A is untouched.

Please advise as none of the cells are merged
 

Attachments

  • EaseUS_2023_10_10_19_03_17.jpg
    EaseUS_2023_10_10_19_03_17.jpg
    13.5 KB · Views: 7

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Which line of code raised the error?

Are any cells in column D merged?

BTW merging cells is almost always a bad practice.
 
Upvote 0
No cells are merged.
The first yellow line was the sorting of column A
 
Upvote 0
Can you run the code below and let us know if any cells are highlighted yellow

VBA Code:
Sub FindMergedcells()
Dim myRng As Range
    For Each myRng In Sheets("COUNTRYLIST").UsedRange
        If myRng.MergeCells Then
            myRng.Interior.ColorIndex = 6
        End If
    Next
End Sub
 
Upvote 0
Can you run the code below and let us know if any cells are highlighted yellow

VBA Code:
Sub FindMergedcells()
Dim myRng As Range
    For Each myRng In Sheets("COUNTRYLIST").UsedRange
        If myRng.MergeCells Then
            myRng.Interior.ColorIndex = 6
        End If
    Next
End Sub

No cells turn Yellow
 
Upvote 0
Im looking now but i use 2007 so need to find out where it is
 
Upvote 0
You can simply use CTRL+F to bring up the FIND menu.
See screenshot

However none of them are merged.

So this below works.

In the main code i added Call FRAME_NUMBER_SORT

In that module i used the same 2 lines of code that was giving the issue.
It works fine & i havent touched any other cells in respect of un merging them

Cheers
 

Attachments

  • EaseUS_2023_10_10_19_34_56.jpg
    EaseUS_2023_10_10_19_34_56.jpg
    68.2 KB · Views: 6
Upvote 0

Forum statistics

Threads
1,215,072
Messages
6,122,968
Members
449,095
Latest member
Mr Hughes

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