• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Code works perfect with the F5 but gives error when pasting behind a button

mdtje

New Member
Code:
Sub EenSiteJaarOverzicht()
OuTravailler3
With Worksheets(" Jaaroverzicht per site")
  Tb = Sheets("DATA").Range("AfkortSites")

  i = Range("B3").Value
  keuzeSite3
  SaveAsPdf (Tb(i, 1))
End With
End Sub
This code works perfectly when using debug (F5) i gets his value
when i want to make the code to run ,and i use a button ,then i is not getting a value
i go to the code and try again with F5 , what do you think NO PROBLEM
I dont know what to do Anymore
 
Mdtje

Firstly, Welcome to the Chandoo.org Forums

What are the two lines
1. OuTravailler3
2. keuzeSite3

Also where is the code?
It should either be in a worksheet module for the worksheet which is calling it or in a code module

Can you post the whole file ?
 
Thx for replying and the welcome

Code:
Sub EenSiteJaarOverzicht()
OuTravailler3
With Worksheets(" Jaaroverzicht per site")
  Tb = Sheets("DATA").Range("AfkortSites")

  i = Range("B3").Value
  keuzeSite3
  SaveAsPdf (Tb(i, 1))
End With
End Sub

Private Sub OuTravailler3()
  Rep = ThisWorkbook.Path
  Rep = Rep & "\pdfsingle\"
  If Dir(Rep, vbDirectory) = "" Then MkDir Rep
End Sub

Sub keuzeSite3()
Sheets(" Jaaroverzicht per site").Activate
Select Case Range("B3").Value
  Case 1
  Range("D3").Value = "ANT"
  Case 2
  Range("D3").Value = "ARL"
  Case 3
  Range("D3").Value = "BNL"
  Case 4
  Range("D3").Value = "BRG"
  Case 5
  Range("D3").Value = "BRU"
End Select
End Sub
hope this helps
 
Hi, mdtje!

Helps a bit but it isn't enough.

As Hui told you... Consider uploading (a) sample file(s) (including manual examples of desired output if applicable), it'd be very useful for those who read this and might be able to help you, relieving the contributor of having to build a test file, if necessary. Thank you.

In this case, we can't test the procedure and we don't know if there're more macros, for example those for worksheet or workbook change events.

Regards!
 
Salut, monalisa!

Merci beaucoup pour la clarification linguistique mais je pense que Hui ne faisait pas référence à la signification des noms de procédure, mais aux contenu.
Dans mon commentaire, je lui ai demandé de monter un dossier, mais je crois (vous) qu'il n'avez pas lu ou l'avez simplement rejeté.

Salutations!

PS: S'il vous plaît utiliser le langage standard du forum. Merci.

-----
Translation monalisa's way :p
-----

Hi, monalisa!

Thank you very much for the linguistic clarification but I think that Hui didn't refer to procedure name meanings but to its content.
In my comment I asked (you) him to upload a file but I believe that (you) he haven't read it or (you) he have simply discarded it.

Regards!

PS: Please use the forum standard language. Thanks.

EDITED (SirJB7)

you by him
 
Last edited:
Sorry did i just offend you??

I study in a French school and hence my classmates often use travailler as their worksheet names lol...

And what/which file you want me to upload??? I already have a ready nagging problem on vba excel, do you want me to send it to you??

Best regards

XOXO

Monalisa :)
 
Hi ,

I ran your code and did not find any problem.

If you say that the variable i is not being assigned an expected value , it may be because you have the code in a module instead of the worksheet where the value is present. The statement :

i = Range("B3").Value

expects the cell B3 in the activesheet to have a value. If this is in a module or in the ThisWorkbook section , and the activesheet does not have any value in cell B3 , then i will remain Empty.

If you want the code to take the correct sheet , based on what you have specified in the With statement , change the above statement to :

i = .Range("B3").Value

Narayan
 
Last edited:
Sorry did i just offend you??
Hi, monalisa!

Absolutely not, no offense taken at all. Just maybe with "Travailler" someone (not Hui, I guess) could have some doubt but with "oui", not even Chandoo would last more than 1/10 sec... :) Ok, he might, ok. :(

The problem is that (your) the posted code seems to work fine if (you) placed it in the related class module (aka the worksheet code area), as NARAYANK991 wrote. But just in case there is more VBA playing around it'd be helpful to could have the sample file.

Have you gone thru this? If not, what're you waiting for? Act as Nike says, just do it!
http://chandoo.org/forum/forums/new-users-please-start-here.14/
There you'll find the guidelines to upload a file, if still necessary. And if you haven't noticed the below button at the right of Post Reply... Yes, that which says "Upload a File", how did you guess it? ;)

Regards!

EDITED (SirJB7)
 
Last edited:
Hi ,

I ran your code and did not find any problem.

If you say that the variable i is not being assigned an expected value , it may be because you have the code in a module instead of the worksheet where the value is present. The statement :

i = Range("B3").Value

expects the cell B3 in the activesheet to have a value. If this is in a module or in the ThisWorkbook section , and the activesheet does not have any value in cell B3 , then i will remain Empty.

If you want the code to take the correct sheet , based on what you have specified in the With statement , change the above statement to :

i = .Range("B3").Value

Narayan
Nayaran thx yo solved it it was indeed
i = .Range("B3").Value that solved it
weirdt that with F5 it did work and did not work behind a button
Any way thx
 
Back
Top