Hi - I'm a VBA programming newbie and could do with some help. I'm sorry if this is a dumb question but I could not google out a solution.
I have written a macro that requires data to be sorted on the basis of two keys. Since I did not know how to start from scratch, I recorded a sort and tried to re-use the code. The modified code is posted below. Before that,
sheetName = worksheet name (e.g. "Sales Data")
colNo1 = 1st sort key (e.g. "C")
colNo2 = 2nd sort key (e.g. "I")
flag = just something I use to prevent the last row from being sorted in some cases
The function lastRowOfWorksheet returns, well, the last row.
Here goes -
Now what's happening is that this VBA sort sometimes works fine and the macro produces the right results. Sometimes the macro doesn't do what it's supposed to. That's because the VBA sort fails to sort the data. When I manually sort the data and run the macro, it produces expected results. I'm not able to understand why the VBA sort is not working at times. The range and the last row function are correct.Please Login or Register to view this content.
Can somebody please point out what the problem could be? My OS is Windows XP and I'm using Office 2007.
Thanks a lot for your time.
Bookmarks