Trying to figure out why my scripts creates hidden and randomly values

most

Board Regular
Joined
Feb 22, 2011
Messages
107
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
  2. Mobile
I have script which acts irrational, it randomly create data.
In trying to figure out why I notice that there a data in a cell which shouldn't be there.

Prtscr 1
Screenshot_3.jpg


Prtscr 2 - When I press Delete on my keyboard on the second row/second column , the text in first column appears.
My conclusion is that the second column row contains something, right?
Screenshot_4.jpg


Debug.Print Len(ActiveCell.Value) returns 0

This is the code, it's secondary important since this post is more about me figuring out how can see hidden characters.
But If anyone see that this generates a hidden character, I of course appreciates feedback. And of course it's a lot of more code.
VBA Code:
'Loop1
  For r1 = 35 To 2 Step -1
  Set c1 = Sheets("P").Range("G" & r1)
   If Not IsEmpty(c1.Value) Then
     If c1.Value = c1.Offset(1, 0).Value Then
       c1.Offset(0, 1).Value = c1.Offset(0, 1).Value + c1.Offset(1, 1).Value
       c1.Offset(1, 1).Value = ""
     Else
     End If
   Else
   End If
  Next r1
'Loop2
  For r2 = 35 To 2 Step -1
  Set c2 = Sheets("P").Range("G" & r2)
   If Not IsEmpty(c2.Value) Then
     If c2.Value = c2.Offset(1, 0).Value Then
       c2.Offset(0, 2).Value = c2.Offset(0, 2).Value + c2.Offset(1, 2).Value
       c2.Offset(1, 2).Value = ""
     Else
     End If
   Else
   End If
  Next r2
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
If you are going to use an image please include the column and row references.
I can't see anything obvious in the code.
• When you look in the cell is there a single quote mark (') in it ?
• if not, how did the data get there, did you copy paste it in from somewhere else ?

For more information see the heading
"There are 3 types of zero-length strings in Excel" at the below link:
 
Upvote 0
No, there are no quote mark (') in it.
How the invisible data get there is what I'm trying figure out.

These are the only lines code I see can write to that column
VBA Code:
      c1.Offset(0, 1).Value = c1.Offset(0, 1).Value + c1.Offset(1, 1).Value
       c1.Offset(1, 1).Value = ""
 
Upvote 0
The big question is, how can there be invisible data in cell and I can't see with i.e Debug.Print Len(ActiveCell.Value)?
 
Upvote 0
Was data copied into the sheet at any point ?
Yes, earlier in the script data is copied. The 'shared lines of code' merge data in the second column. Much like this post.
But if I "Debug Step into (F8)" I can that it's the 'shared lines of code' which creates the mystery data. So before, none of the lines have "empty" data has it is after.
 
Upvote 0
I can't see the code that you have in Post #1 causing that issue.

If you change the code to add the lines in blue, does it make any difference.
Rich (BB code):
     If c1.Value = c1.Offset(1, 0).Value Then
       c1.Offset(0, 1).Value = c1.Offset(0, 1).Value + c1.Offset(1, 1).Value
       c1.Offset(1, 1).Value = ""
       With c1.Offset(, 1).Resize(2)
            .Value = .Value
       End With
     End If
 
Upvote 0
I can't see the code that you have in Post #1 causing that issue.

If you change the code to add the lines in blue, does it make any difference.
Rich (BB code):
     If c1.Value = c1.Offset(1, 0).Value Then
       c1.Offset(0, 1).Value = c1.Offset(0, 1).Value + c1.Offset(1, 1).Value
       c1.Offset(1, 1).Value = ""
       With c1.Offset(, 1).Resize(2)
            .Value = .Value
       End With
     End If
No, that did not help.
BUT, I changed from "" to Null and that seems to fixed the issue.

c.Offset(1, 1).Value = Null

And I also made this secondary check, but with the Null-change it's redundant.
VBA Code:
   'If Not IsNumeric(c.Value) Then
   '    c.Value = ""
   '    c.Offset(0, 1).Value = ""
   '    c.Offset(0, -1).Value = ""
   'End If
 
Upvote 0
Glad you found something that works for you.
Without access to you workbook I can't trouble shoot it any further.
I would probably use = Empty rather than = Null. The worksheet doesn't really have the concept of Null and to test for it to be Empty or in your case Null cell you would use IsEmpty. ie IsEmpty will return True but IsNull will return False.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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