View Single Post
  #17   Report Post  
sumesh56 sumesh56 is offline
Senior Member
 
Posts: 118
Default

Quote:
Originally Posted by joeu2004[_2_] View Post
"sumesh56" wrote:
i copy pasted your code to a new sheet at the end of the sheets already
in my file named testseatingplan210314.and when i run the macro it gives
me error message, it says "can't excecute code in break mode".in the
code the word befo is highlighted.(loop until i=nData
sort by roll number
sheets.Add befo =sheets(1)


First, Download my file "test seating plan 210314.xlsm" again; same URL:
https://app.box.com/s/f7yddu2xcrki8wx5mr8t.

I simplifed things to make it easier to copy-and-paste the macro. One
macro: the one that sorts; I think you'd prefer that. No dependency on
timer macros.

I also corrected the misnamed variables distribTitle and seatingTitle. The
code worked before as written. But it is like having a variable "two" whose
value is 3. Misleading! My bad!

Also, the updated file shows the workbook in its initial state: just two
worksheets, and the Distribution worksheet has no data in columns C:E.

You can run the macro and see how it changes the workbook, namely: it
creates a new worksheet called "NEW Distribution ...", and it leaves the
original Distribution worksheet unmodified.

-----

That has anything to do with your immediate problem.

I don't know why you were in break mode. Did you stop the execution of a
macro using a Stop statement, a breakpoint (F9) or single-stepping (F8)? Or
did you get a run-time error and click on Debug instead of End?

To avoid the problem, click on Run, then Reset before pasting or importing
the macro code into a workbook.

Also, the simplified macro noted above will probably avoid a run-time error
when you copy-and-paste or import the code into other workbooks.

-----

You do not need to copy the macro into each sheet module. In fact, the
implementation probably does not work in a sheet module.

It is sufficient (and probably necessary) to have one copy of the macro in a
normal module.

To copy the macro into a workbook:

1. In VBA, click on Insert, then Module.
2. Copy the code text, and paste into the new module.

Alternatively, save ("export") the code module one time by doing the
following:

1. In VBA, with the desired module selected, click on File, then Export.
2. Navigate to a folder of your own, usually under My Documents.
3. Change Module2.bas in the File Name field to something appropriate, e.g.
makeDistrib.
4. Click on Save.

Or you can download makeDistrib.bas from
https://app.box.com/s/buzzwbxemee7xgnr4dgz.

Then, to import the code module into a workbook:

1. In VBA, click on File, Import.
2. Navigate to the folder where you saved the module.
3. Find and double-click on the ".bas" file that you saved.

-----

Hope that helps. Sorry this is so difficult. But I believe a VBA solution
is the best, if not the only, way to do what you want.
thanks a lot for the reply and guidance. let me check and report back. have a nice day.