Macro help - use to work now getting an error

lwilt

Board Regular
Joined
May 16, 2013
Messages
187
I'm using a macro to transpose my data. I realized that the 3rd column isn't sorted correctly so when it transpose it the data ends up out of place. So I sorted the file by the first 3 columns in order to keep the grouping together and to now have the 3rd column sorted in descending order but its causing my macro to get an error message now about not being able to run. If I don't sort it runs fine but I don't get the desired outcome. here is the macro:

Sub TransposeQandP()
Dim X As Long, Ar As Range
With Range("A1:A" & Cells(Rows.Count, "B").End(xlUp).Row).SpecialCells(xlBlanks)
For Each Ar In .Areas
For X = 1 To Ar.Count
Ar(1).Offset(-1, Cells(Ar(1).Offset(-1).Row, Columns.Count).End(xlToLeft). _
Column).Resize(, 2).Value = Ar(1).Offset(X - 1, 2).Resize(, 2).Value
Next
Next
.EntireRow.Delete
End With
End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
What is the error message and which line is highlighted when you get it?
 
Upvote 0
I get an error message about not having enough Ram to complete the process even though that excel doc is the only thing open when doing it. But if I run it without sorting it works fine every time so I'm assuming it's not really an issue with Ram but with the macro itself not liking the fact that I sorted the file before running it.
 
Upvote 0
I get an error message about not having enough Ram to complete the process even though that excel doc is the only thing open when doing it. But if I run it without sorting it works fine every time so I'm assuming it's not really an issue with Ram but with the macro itself not liking the fact that I sorted the file before running it.

If the macro compiles and runs ok before you sort, it's hard to see why a memory issue arises when you simply sort some of the data. Have you tried quitting Excel and restarting it?
 
Upvote 0
I have and it didn't work. I even tried copying the part I'm doing the macro on into a new excel file with no other programs open and running the macro on the sorted data and it still gave me an error....then I immediately ran the original non sorted and works fine.

really confused with what is happening with it
 
Upvote 0
Is there a way to attach a file so someone can see if I just goofed up somewhere because it's make no sense how sorting is messing this up
 
Upvote 0
Is there a way to attach a file so someone can see if I just goofed up somewhere because it's make no sense how sorting is messing this up
Can you post some sample data before and after sorting for the 3 columns?
 
Upvote 0
playing with the sorting it appears I have found the problem....it seems to sort in a weird way.

skusku1QP
AF121C60AF121C60
AK18025AK1802569
AK18025128.5
AK18025248
AK18025367.25
AB411FIRAB411FIR354
AB411FIR652
AB411FIR1250
AB411FIR2448
AE120AUSAE120AUS360
AE120AUS656.25
AE120AUS1253.13
AE120AUS2450
AY521AY52115156
AY5219159
AY5216162
AY5213165
AY521
AY521
AY521
AY521
AY521
AY521
AY521
AY521
AY521
AY521
AY521
AY522AY5223183.5
AY5226179
AY5229169
AY52215163
AY522
AY522
AY522

<colgroup><col span="2"><col><col></colgroup><tbody>
</tbody>

How should I sort the 4 columns so that columns A and B look basically the same but it puts column c in descending order?
 
Upvote 0
If you sort column C, there's no way to keep you data together w/o affecting cols A & B.

You might be better off starting a new thread explaining in detail what you want to accomplish with before and after examples of your data.
 
Upvote 0
if I removed column 1 from the data and just kept the other 3 columns what would I need to change in the macro for it to work the same way as before?
 
Upvote 0

Forum statistics

Threads
1,203,565
Messages
6,056,102
Members
444,846
Latest member
pbailey

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