+ Reply to Thread
Results 1 to 4 of 4

The VBA Code that I have writen is not right.

  1. #1
    Registered User
    Join Date
    11-09-2014
    Location
    drenthe
    MS-Off Ver
    2013
    Posts
    5

    The VBA Code that I have writen is not right.

    Hello,

    I would like some help with the following. I try to develop myself in VBA code for my job.

    I'm working on a program code that does calculation on 64 fields, for example an chessboard.
    On field 1 lies 1 object, on field 2 lie 2 objects, on field 3 lie 4 objects and on field 4 lie 8 objects. So in total there are 15 objects on those 4 fields.

    I want to write the program in such a way that I can beforehand type in an inputbox how many objects I have and how many fields can be filled with this number.

    I've written the following code. Can you tell me which mistake I'm making?

    -----------------------
    Sub schaakbordv2()

    'hoeveel graankorrels ter beschikking'"
    'bereken hoeveel velden er gevuld kunnen worden'
    'Het bestaat uit 64 velden: 8 horizontale rijen en 8'
    'geef aantal korrels in msgbox'


    Dim veldnr As Byte, aantalkorrels As Single, totaalkorrels As Single, teller As Integer

    totaalkorrels = InputBox("hoeveel graankorrels heb je")

    aantalkorrels = 1

    For totaalkorrels = 1 To veldnr

    aantalkorrels = 2 ^ veldnr

    totaalkorrels = totaalkorrels + aantalkorrels
    veldnr = veldnr + 1

    Next totaalkorrels


    MsgBox ("aantalvelden " & veldnr)

    End Sub

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,572

    Re: The VBA Code that I have writen is not right.

    Number of fields = roundup(log10(num objects)/log10(2))
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    11-09-2014
    Location
    drenthe
    MS-Off Ver
    2013
    Posts
    5

    Re: The VBA Code that I have writen is not right.

    Thanks for the help

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: The VBA Code that I have writen is not right.

    8 would occupy 4 cells, no?

    Row\Col
    A
    B
    C
    1
    0
    0
    B1: =CEILING(LOG(A1+1, 2), 1)
    2
    1
    1
    3
    2
    2
    4
    3
    2
    5
    4
    3
    6
    5
    3
    7
    6
    3
    8
    7
    3
    9
    8
    4
    10
    9
    4
    11
    10
    4
    12
    11
    4
    13
    12
    4
    14
    13
    4
    15
    14
    4
    16
    15
    4
    17
    16
    5
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Compatibility issue with code writen in excel 2007 and used in 2010
    By cdn_medic in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-03-2014, 06:32 PM
  2. Macro writen macros for objects will not run
    By Leon V (AW) in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-04-2012, 05:59 AM
  3. Can this program be writen in excel?
    By dandepas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-27-2012, 11:38 AM
  4. summing data writen by a excel vba form
    By FrankCF in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-20-2008, 09:37 AM
  5. formula writen as vba
    By fluffy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-24-2007, 11:07 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1