3

There's a bug or error in the code or workbook somewhere but I can't seem to find it or understand why is this happening.

What's happening is There's a userform which has a button to :

  1. Select a cell from sheet2
  2. Put the selected cell value in sheet1 cell B10 which is a dropdown menu
  3. Unloads the form return to sheet1 and select a cell which is described in the code as sheet1.B26 now .

Now as soon as the form is gone. If I click in the sheet1.B26 selected cell and write something press {TAB} the content from that cell is transferred to the exact same cell but on sheet2 automatically and sheet1.B26 cell is empty .

This happens only once if I immediately start writing in the selected cell when the form is gone.

There is no code/formula in the worksheet or workbook or module that should describes this action.

This is bugging me for a week but I couldn't find solution anywhere.

Workbook if you wish to download it and try it.

Video Description of the error

To recreate this:

  1. Go to sheet1
  2. Fire up the form using very first button on sheet1 which has "Klant zoek" text on it.
  3. Press the button which say "selecteer" on the form.
  4. Without selecting any other cell Enter something in last selected cell by the macro and press tab.

P.S. - I didn't write any of the code in that workbook I am just assigned to debug it.

Stupid_Intern
  • 3,382
  • 8
  • 37
  • 74
  • Nope there isn't any. I added the link to download the workbook if you wish to try it you can. – Stupid_Intern Jun 11 '16 at 04:18
  • @DirkReichel Thanks for trying. You have to follow the exact sequence. When the form is closed. Do not do anything else just click in the cell write anything and press tab. – Stupid_Intern Jun 11 '16 at 05:23
  • I have done it exactly as described... I also tried to alter it to get your behavior, but no luck... it always acts like it should be. Click button -> click selecteer -> hit some random letters like "kljnvrgkvjprswnrw" -> hit tab. the text stays in sheet1.B26 and C26 now is selected (due to tab)... sheet 2 remains unchanged – Dirk Reichel Jun 11 '16 at 05:27
  • What was the value in cell b10 of sheet1 after everything ? – Stupid_Intern Jun 11 '16 at 05:31
  • The value of the cell selected in sheet2 before the sequence started... in my case "Customer 17" – Dirk Reichel Jun 11 '16 at 05:35
  • https://www.dropbox.com/s/k12lr63bjn4clg5/bug.mp4?dl=0 Here's the video showing the error – Stupid_Intern Jun 11 '16 at 05:36
  • I'll run some checks... may take a while (still I do not get this behavior) – Dirk Reichel Jun 11 '16 at 05:49
  • Hey, even I tried your workbook but everything seems to be fine as @DirkReichel stated. Text I entered in Cell B26 of sheet1 remains as it is and sheet2 unchaned. Sheet1.B10 displays the details of the cell selected in Sheet2 when `Selecteer` is clicked. – Mrig Jun 11 '16 at 07:54
  • @Mrig Thanks for trying I don't know why its not the case on your machines. Can you save the file and send it I will try that as well just in case. Is it anyway dependent on xl version or OS ? I have xl 2013 running on win 10. – Stupid_Intern Jun 11 '16 at 07:57
  • I've shared the [workbook](https://dl.dropboxusercontent.com/u/85372600/Facturen_en_Offertes.xlsm) see if it helps. I am using Excel 2007. – Mrig Jun 11 '16 at 08:03
  • @Mrig Thanks but no luck same problem :( did you do exactly as you saw in the video ? – Stupid_Intern Jun 11 '16 at 08:09
  • Exactly the same, step by step. – Mrig Jun 11 '16 at 08:10
  • Give it a try on different machine. – Mrig Jun 11 '16 at 08:14
  • @Mrig I did same error – Stupid_Intern Jun 11 '16 at 08:26
  • Have you checked your addins? – Dirk Reichel Jun 11 '16 at 13:09
  • No what's that and how to check it ? Which add-in to check ? – Stupid_Intern Jun 11 '16 at 13:11
  • File -> options -> addins tab... check if something doesn't look like default... thats the last idea i got – Dirk Reichel Jun 11 '16 at 13:15
  • There were couple of add-ins that I installed so it would not look like default I'll try re-installing excel – Stupid_Intern Jun 11 '16 at 13:20
  • This is a long shot but I don't want to explain it in an answer if its not right (although I'm pretty confident). I once had a language issue with R1C1 addressing. In Dutch its not R for row and C for Column, its R for row (Rij) and K for column (Kolom). Now I was using `indirect` so it might be different but parse the code and change things like `Range("B48").FormulaR1C1 = "=VLOOKUP(R18C2,Bedrijfsgegevens!R[1]C:R47C25,16,FALSE)"` to `Range("B48").FormulaR1C1 = "=VLOOKUP(R18C2,Bedrijfsgegevens!R[1]C:R47K25,16,FALSE)"` – Gary Evans Jun 11 '16 at 20:58
  • @GaryEvans So you are saying I should replace the `C` with `K` ? – Stupid_Intern Jun 11 '16 at 21:10
  • Yes, my above example has a flaw in it `"=VLOOKUP(R18C2,Bedrijfsgegevens!R[1]C:R47C25,16,FALSE)"` to `Range("B48").FormulaR1C1 = "=VLOOKUP(R18K2,Bedrijfsgegevens!R[1]C:R47K25,16,FALSE)". I'll be excited if you're doing this now it, 22:13 but I want this to be the answer! – Gary Evans Jun 11 '16 at 21:12
  • So shouldn't I change this `Range("B48").FormulaR1C1` to `Range("B48").FormulaR1K1` that as well ? Actually it would be great if you can post a little detailed answer sorry its hard to follow. Thank you – Stupid_Intern Jun 11 '16 at 21:20
  • @GaryEvans I changed the code but still no luck perhaps I am doing something wrong. If you can correct it and share the file with me that would be great. – Stupid_Intern Jun 12 '16 at 06:51
  • @newguy: Can you please check your name definitions? In `Name Manager` check for names with bad definitions, such which results in #REF! errors. For example there is a name `Logokeuze` defined twice, one time with scope worksheet "Facturen en Offertes" and one time with scope the whole workbook. The one for the whole workbook is bad defined. Delete this and try again. – Axel Richter Jun 12 '16 at 07:03
  • @AxelRichter I deleted the ones with error and the Logokeuze it doesn't works. By the way can you confirm whether you got the error too on your machine ? – Stupid_Intern Jun 12 '16 at 07:17
  • I'll write something up tonight, can you confirm if its ever worked for you and if something was changed, or of it work for someone else but not you, are you both using the same language on your machines? – Gary Evans Jun 12 '16 at 07:41
  • @newguy: No, I can't reproduce the behavior. But I know that bad name definitions may lead to such unexpected behaviors since names may be involved in much many calculation chains. – Axel Richter Jun 12 '16 at 07:42
  • @newguy: In your video the file is opened in [Protected View][https://support.office.com/en-us/article/What-is-Protected-View-d6f09ac7-e6b9-4495-8e43-2bbcdbcb6653] first. What happens if you download it first and then open it from your local drive? – Axel Richter Jun 12 '16 at 07:56
  • @AxelRichter No that's not a problem I saved it on my local drive and got the same error. – Stupid_Intern Jun 12 '16 at 08:15
  • It's not the first time I see it in 2013. It happens when the form is Modal, is called from Form button or shape click event, and form changes active sheet. Some workarounds: a) use activeX buttons b) make form modeless. – BrakNicku Jun 14 '16 at 04:34
  • 2
    Did you try changing `Zoekklantform.Show` to `Zoekklantform.Show vbModeless`? in `Sub zoekklant()`? If it works, I'll post an answer with links to same problem description and a workaround to show form modal. – BrakNicku Jun 14 '16 at 17:49
  • @BrakNicku YOU ARE AWESOME that worked don't know why and how but it stopped that error sure please post it as answer but with an explanation if possible Thanks :) – Stupid_Intern Jun 14 '16 at 18:06
  • Unfortunately I can't _explain_ it, as it is probably a bug in Excel 2013, but tomorrow I'll post it as an answer with some ways to workaround it - showing modeless form is far from perfect in many situations. – BrakNicku Jun 14 '16 at 18:13

4 Answers4

2

I had a similar issue with an Excel solution I built a while ago that was shared across countries, the issue in this case was with R1C1 address notations and I think it may be the same here, but it can't be easily tested from one local machine, read and try the below.

To clarify, R1C1 address notation refers to row and column by name, so cell C4 has an R1C1 address notation of R4C3

The specific issue I had involved the use of INDIRECT, for example =INDIRECT("'Sheet1'!R21C10", FALSE)

This worked for a number of the countries but failed for those where 'Row' did not begin with an 'R' and 'Column' did not being with a 'C'.

Nederlands is 'Rij' and 'Kolom' so the notation had to be R21K10 for it to work. I.e. =INDIRECT("'Sheet1'!R21K10", FALSE)

The current list I have for this is: -

Language    Row     Column  Full Terms
Deutsch     Z       S       Zeile-Spalte
English     R       C       Row-Column
Español     F       C       Fila-Columna
Français    R       C       Rangée-Colonne
Italiano    F       C       Fila-Colonna
Nederlands  R       K       Rij-Kolom
Polski      R       K       Rząd-Kolumna
Português   L       C       Linha-Coluna
Türkçe      S       S       Sira-Sütun

This issue was only experienced in formulas and not via VBA, however code found in Blad1 (Facturen en Offertes)1 > betalingstermijn (as an example) uses VBA to set a formula in a cell, so the issues align in this respect.

The changes that would be needed would be to change all lines that place R1C1 notation into a formula to the required column initial, examples below.

English (No Change)     
Range("B48").FormulaR1C1 = "=VLOOKUP(R18C2,Bedrijfsgegevens!R[1]C:R47C25,16,FALSE)"

Español (R to F, C no change)
Range("B48").FormulaR1C1 = "=VLOOKUP(F18C2,Bedrijfsgegevens!R[1]C:F47C25,16,FALSE)"

Français (No Change)
Range("B48").FormulaR1C1 = "=VLOOKUP(R18C2,Bedrijfsgegevens!R[1]C:R47C25,16,FALSE)"

Nederlands  (R no change, C to K)
`Range("B48").FormulaR1C1 = "=VLOOKUP(R18K2,Bedrijfsgegevens!R[1]C:R47K25,16,FALSE)"

NOTE: You would not be changing the command name .FormulaR1C1, just the value passed into it.

You can isolate this to test by doing the following in a new sheet.

  1. Enter the below data, ending in 4 populated cells

(Sample table)

 |  A  |   B   |
1|First|Second |
2|Third|Forth  |
  1. In an empty cell enter the formula =INDIRECT("R1C1",FALSE) (Include the double quotes)

In English this will result in 'First' in Netherlands (Dutch) this will show #REF.

This may not be the only issue but it is one I've encountered in the past and owing to the difficulty in reproducing the issue, I would recommend trying to rule it out at least.

Gary Evans
  • 1,850
  • 4
  • 15
  • 30
2

The issue is that it only looks as the sheet "Facturen en Offertes"-B26 is active. It is actually "Klanten"-B26 that is active. It is solved by adding "vbModeles" to the call to the user form.

Sub zoekklant()
    Zoekklantform.Show vbModeless
End Sub
Fredrik
  • 306
  • 1
  • 7
  • Perhaps [this lecture](https://msdn.microsoft.com/en-us/library/aa263470(v=vs.60).aspx) would complement the answer provided – Sgdva Jun 15 '16 at 15:05
2

The problem described in question can be easily reproduced in Excel 2013, it doesn't occur in earlier versions. I did not have a chance to test it in 2016. Similar problem can be found here and here.

There are 3 parts common to all cases:

1) UserForm is shown using Form Button or Shape click event handler

2) UserForm is modal (vbModal is default value of UserForm.Show parameter)

3) UserForm code changes active sheet

As a result, sheet activated by UserForm is shown, but it is not really active. Any edits made to it appear in previously (before UserForm was shown) active sheet.

It is a bug in Excel 2013, the easiest workarounds to solve it are:

1) Use ActiveX Button to show the form

2) Show modeless form: UserForm1.Show vbModeless

But what if we cannot use ActiveX and need modal form? This answer suggests hiding and showing ActiveWindow, but it did not work for me.

The only workaround to show modal form without ActiveX working for me is:

To show modal UserForm1, create another empty UserForm2 with Activate event handler:

Private Sub UserForm_Activate()
  'hide form
  Me.Left = -1000
  'show target form 
  UserForm1.Show
  Unload Me
End Sub

And instead of:

UserForm1.Show

Use:

UserForm2.Show vbModeless 
Community
  • 1
  • 1
BrakNicku
  • 5,935
  • 3
  • 24
  • 38
0

I've experienced a similar issue before as a result of creating a new sheet. In my situation, it had to do with excel having two sheets simultaneously selected, and as such it always chose to write on the earliest one in the sequence until I had fiddled around selecting different sheets to reset the selection. My solution was to simply have the sub select a different sheet and then reselect the desired sheet, resetting the double selection issue.

RGA
  • 2,577
  • 20
  • 38
  • Indeed if more than one sheet is selected and a cell is updated, the cell on both sheets are updated to be the same, or at least that is how it is in Excel 2010 for me. However the issue here is that its ig leaving the cell he is in and showing up on the cell in the other sheet, so they don't match – Gary Evans Jun 13 '16 at 12:52
  • @GaryEvans In my experience (working with 2013), only the first sheet is written on, and interestingly regardless of which cells I select on the second sheet, everything is written on the first sheet until I select a non-selected sheet to reset the issue – RGA Jun 13 '16 at 12:54