Data integrity breakdown with VBA macro adding sheets?

PeterPh

New Member
Joined
Nov 28, 2012
Messages
7
Hello All,

I have a VBA macro that takes subsequent data sets, runs each through an algorithm, takes a screen print of the result and pastes to each newly created sheet.

The issue I’m trying to get my head around is that after Sheet197 is created as it should be, Sheet198 is a repeat of the image on Sheet197, and then all subsequent sheets have images that are displaced by 1. This exact situation occurs on all of my PCs and laptop, regardless of the amount of RAM and processor power each have.

This issue obviously has nothing to do with the hardware and the VBA code seems solid, so it appears to be a quirk of Excel. Has anybody else come across this type of issue before and if so, can you shed some light on it?

Thanks very much,

Peter.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I think I would try to make an in depth analysis of what the code does on iteration 197 and 198. One way to do that is to put a counter in the loop and use the stop command to halt the macro on iteration 186. Then you can step through one line at a time for iteration 197 and 198 to see exactly what happens on those iterations. You might be surprised.

Example:
Dim counter As Long
counter = 0
For i = 1 To 200 'Start loop
Set sh = Sheets.Add 'Create new sheet
sh.Name = New & i
'Do stuff here
counter = Counter + 1
If counter = 196 The Stop 'Suspend code execution on iteration 196
Next
Example:

Iteration 197 will most likely be routine, except for the lines after copy, or iteration 198 in the lines before copy. Not having the code to look at, I can only surmise that something takes place based on a value some where outside the code in the loop. But it should show up as you step through the code. Could be event code being triggered. Then again, you might find nothing, but it don't hurt to try.
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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