View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Polarbear Polarbear is offline
external usenet poster
 
Posts: 7
Default my macro is clearing the wrong sheet

I fixed and it works perfectly I guess like you said when I unhide sheet my
cursor is on the new sheet but it cleared the same cells on both sheets I
think. I re wrote the macro to open all hidden sheets first, then when i
selected them by the tab the macro recorded correctly. Thanks for your help.

"Polarbear" wrote:

Thanks you guys I will fix it in the morning


"Rowan" wrote:

To add to David's comments, with VBA you can manipulate the sheets without
actually
selecting or unhiding them. So a chunk of your code eg:

Sheets("Misc policies & procedures ").Visible = True
Range("D22").Select
Selection.ClearContents
Range("D3:D19").Select
Range("D19").Activate
Selection.ClearContents
Range("D3").Select
Sheets("Misc policies & procedures ").Visible = False

could be rewritten as:

With Sheets("Misc policies & procedures ")
.Range("D22").ClearContents
.Range("D3:D19").ClearContents
End With

I hope this helps
Rowan

"Polarbear" wrote:

Not sure how to do that -- I'm not too good at writting macros other than
just recording what I do -- mistakes scrolling and all -- I printed the macro
it took up over two pages but i can try to past it here if it fits ?

Range("I4:J4").Select
Selection.Copy
ActiveWindow.SmallScroll ToRight:=6
ActiveWindow.SmallScroll Down:=9
Range("W24:X24").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Range("U26:Z26").Select
Application.CutCopyMode = False
Selection.Copy
ActiveWindow.SmallScroll ToRight:=-9
ActiveWindow.SmallScroll Down:=22
Range("B35:G35").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Range("B26:G35").Select
Range("F35").Activate
Application.CutCopyMode = False
Selection.Sort Key1:=Range("F26"), Order1:=xlDescending, Key2:=Range( _
"D26"), Order2:=xlDescending, Header:=xlGuess, OrderCustom:=1,
MatchCase _
:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal
Range("D31:E31").Select
Sheets("Shift Leader Test").Visible = True
Sheets("Menu Standards").Visible = True

Range("B6,B6:C14,E6:F16,H6:I15,K6:L13,B20:C24,E22: F27,H21:I24,K19:L25").Select
Range("K19").Activate
ActiveWindow.SmallScroll Down:=15
Range( _

"B6,B6:C14,E6:F16,H6:I15,K6:L13,B20:C24,E22:F27,H2 1:I24,K19:L25,B30:C35,E33:F39,H30:I33,K31:L39,H39: I43,B41:C49,E45:F51,H49:I57,K45:L52,B55:C61,E57:F6 2" _
).Select
Range("E57").Activate
Selection.ClearContents
ActiveWindow.SmallScroll Down:=9
Range("E68").Select
Selection.ClearContents
Sheets("Time, temp & thawing").Visible = True
Range("D41").Select
Selection.ClearContents
Range("D3:D38").Select
Range("D38").Activate
Selection.ClearContents
ActiveWindow.SmallScroll Down:=-36
Range("D3").Select
Sheets("Misc policies & procedures ").Visible = True
Range("D22").Select
Selection.ClearContents
Range("D3:D19").Select
Range("D19").Activate
Selection.ClearContents
ActiveWindow.ScrollRow = 12
ActiveWindow.ScrollRow = 11
ActiveWindow.ScrollRow = 10
ActiveWindow.ScrollRow = 9
ActiveWindow.ScrollRow = 8
ActiveWindow.ScrollRow = 7
ActiveWindow.ScrollRow = 6
ActiveWindow.ScrollRow = 5
ActiveWindow.ScrollRow = 4
ActiveWindow.ScrollRow = 3
ActiveWindow.ScrollRow = 2
ActiveWindow.ScrollRow = 1
Range("D3").Select
Sheets("food handling ").Visible = True
Range("D25").Select
Selection.ClearContents
Range("D3:D22").Select
Range("D22").Activate
Selection.ClearContents
ActiveWindow.LargeScroll Down:=-2
Range("D3").Select
Sheets("guest service").Visible = True
Range("D3:D22").Select
Selection.ClearContents
ActiveWindow.LargeScroll Down:=2
Range("D25").Select
Selection.ClearContents
ActiveWindow.LargeScroll Down:=-1
ActiveWindow.ScrollRow = 9
ActiveWindow.ScrollRow = 8
ActiveWindow.ScrollRow = 7
ActiveWindow.ScrollRow = 6
ActiveWindow.ScrollRow = 5
ActiveWindow.ScrollRow = 4
ActiveWindow.ScrollRow = 3
ActiveWindow.ScrollRow = 2
ActiveWindow.ScrollRow = 1
Range("D3").Select
Sheets("Shift Leader Test").Select
Range("B4").Select
Selection.ClearContents
Range("D4").Select
Selection.ClearContents
ActiveWindow.SmallScroll Down:=6
Range("D19:F19").Select
Selection.ClearContents
Sheets("total score ").Select
ActiveWindow.SmallScroll Down:=-15
Sheets(Array("food handling ", "Misc policies & procedures ", _
"Time, temp & thawing", "Menu Standards", "total score ")).Select
Sheets("total score ").Activate
ActiveWindow.ScrollWorkbookTabs Sheets:=-1
ActiveWindow.ScrollWorkbookTabs Sheets:=-1
Sheets(Array("guest service", "food handling ", "Misc policies &
procedures ", _
"Time, temp & thawing", "Menu Standards", "total score ")).Select
Sheets("total score ").Activate
ActiveWindow.SelectedSheets.Visible = False
ActiveWindow.SmallScroll Down:=-21
Range("B4").Select
ActiveWorkbook.Save
End Sub


"Tim Williams" wrote:

post the problem code

Tim

"Polarbear" wrote in message
...
I wrote a multiple choice tests in excel, it's 7 pages multiple
choice with
in cell pull down answer selections. It's also timed which affects
your score
if your fast or slow. It also keeps track of the top 10 scores. It
has 6
macros that record the time, hide the sheet your one and open the
next sheet.
The scores, including times and top 10 are listed on the final sheet
which
is just a total sheet. It works perfectly up to that point -- I
tried to
record one last macro to reset it ie add new results to top ten
list -- print
totals, clear answers, and save it blank on the first page ready
for some
one else to take. The final macro I have written about 6 times I
hit record
do everything I want it to do, but when i run it, it randomly
clears most of
the cells on the total sheet. The total sheet is not selected when
I'm
clearing the others. I know it's a lot to ask but I'm going crazy
can someone
steer me in the right direction ?