dcsimg
Results 1 to 7 of 7

Thread: [Vb.net] Why this code not runnig? [Excel]

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2018
    Posts
    4

    Question [Vb.net] Why this code not runnig? [Excel]

    Hello. I wanna run this code on Excel vba. I have another codes and they runs, just this code ( red line ) not working. Can anyone help me?




    If Sheets("bilgiler").Cells(7, 2).Value <> "Hayır" Then
    k = Mid(Sheets("bilgiler").Cells(7, 2).Value, 1, 1) * 1 + 1

    Sheets("OPTİK FORMLAR").Range(Sheets("OPTİK FORMLAR").Cells(2, k), Sheets("OPTİK FORMLAR").Cells(6, k)).Copy
    wrdapp.Selection.PasteSpecial Link:=False, DataType:=4


    i = .InlineShapes.Count
    With .InlineShapes(i)
    .Height = AspectHt(.Width, .Height, genislik)
    .Width = genislik
    End With
    End If

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    32,752

    Re: [Vb.net] Why this code not runnig? [Excel]

    While the subject says .NET, the code is VBA, and the text talks about VBA, so it's not .NET, and the thread has been moved to Office Development, which is the right place for VBA questions.

    As for the question, what is that expected to do? Mid() will give you a string. Presumably, you expect that string to be a number, since you then multiply and add it, but it's really a string. I don't know how VBA handles an implicit conversion from a string to an integer, and I don't know what it does if it fails, but in any case you multiply by 1, which is pretty useless, so what's that supposed to do?

    I would say that you should put a breakpoint on the line in question and take a look at what

    Mid(Sheets("bilgiler").Cells(7, 2).Value, 1, 1)

    holds. The easiest answer is that it doesn't hold what you expect it to hold, so that's the first thing to look at. Second, what do you expect to accomplish by multiplying by 1?
    My usual boring signature: Nothing

  3. #3
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,545

    Re: [Vb.net] Why this code not runnig? [Excel]

    Works fine for me. As long as the first character in B7 is a number. What do you have in B7?

    Also, like SH says, there's no point in multiplying by 1. Are you thinking that will make it an integer somehow?

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2018
    Posts
    4

    Re: [Vb.net] Why this code not runnig? [Excel]

    hello, sory for my english. b7 is 25. If you need have code, ı have upload it.https://yadi.sk/d/UG24aol44_vB5A

  5. #5
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,534

    Re: [Vb.net] Why this code not runnig? [Excel]

    First Line: He checks if his Cell (7,2) is not equal to "Hayir" (a STRING!!)
    Next Line: If Cell (7,2) is not equal to "Hayir" (say: it's equal to "Bollocks"), he's doing numerical calculations with the First Character of the Value of Cell (7,2) (Why Mid instead of Left?)
    Now, if he's checking, his cell doesn't contain a specific text, why would you expect there being a numerical value instead????
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2018
    Posts
    4

    Re: [Vb.net] Why this code not runnig? [Excel]

    Hello. I chanced code. I was delete this piece "k = Mid(Sheets("bilgiler").Cells(7, 2).Value, 1, 1) * 1 + 1" and i wrote "k=4" ( pic1 ). Its run true for nowly if i run from excel. Occasional blank picture coming if i run from vbnet( pic2 ). How do I add an extra page to the excel and fit picture on the page? ( pic 3 )
    pic1 :
    Name:  2018-11-29 14_57_43-Microsoft Visual Basic - Sinav Yapici.xlsm - [Module2 (Code)].jpg
Views: 20
Size:  17.3 KB

    pic2:
    Name:  2018-11-29 14_53_20-Belge1 - Microsoft Word.jpg
Views: 20
Size:  10.6 KB

    pic3:
    Name:  2018-11-29 15_15_59-Belge1 - Microsoft Word.jpg
Views: 20
Size:  21.3 KB
    Last edited by TrueFalse.sys; Nov 29th, 2018 at 08:18 AM. Reason: k=4

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2018
    Posts
    4

    Re: [Vb.net] Why this code not runnig? [Excel]

    Hello. I chanced code. I was delete this piece "k = Mid(Sheets("bilgiler").Cells(7, 2).Value, 1, 1) * 1 + 1" and i wrote "k=4" ( pic1 ). Its run true for nowly. Occasional blank picture coming ( pic2 ). How do I add an extra page to the excel and fit picture on the page? ( pic 3 )
    pic1 :
    https://i.hizliresim.com/v6QJbz.jpg

    pic2:
    https://i.hizliresim.com/nQ5JRV.jpg

    pic3:
    https://i.hizliresim.com/162GLj.jpg
    Last edited by TrueFalse.sys; Nov 29th, 2018 at 07:57 AM. Reason: deleted

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width