+ Reply to Thread
Results 1 to 8 of 8

Error with distribution code

  1. #1
    Registered User
    Join Date
    04-23-2014
    Location
    Delhi
    MS-Off Ver
    Excel 2003
    Posts
    25

    Error with distribution code

    Dear VBA Experts
    I have written a code for equal distribution of Budget Data based on condition.

    The user will enter annual budget number in Column K (highlighted in Green) and based on condition in Column N (highlighted in Yellow), the data will be divided by 12 and it need to be equally distributed from Colum P to Column AA. The condition for distribution is ‘Y’ (Yes)/ ‘N’ (No).

    [Sub BudDist()
    Dim myCell As Range
    Dim Data As Long
    Dim lr As Long
    Dim a

    lr = Cells(Rows.Count, 11).End(xlUp).Row
    For Each myCell In Range("K39:K" & lr)
    If UCase(myCel.Offset(, 3).Value) = "Y" Then
    Data = myCell.Value / 12
    a = myCell.Row
    Range("P" & a & ":AA" & a).Value = Data

    Next myCell
    End Sub]



    Error.jpg


    Please help me fix the error. The screenshot of the error is attached.

    Thanks,
    Nisha

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Error with distribution code

    Is missing the "End If"

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

    Re: Error with distribution code

    Please take a few minutes to read the forum rules, and then edit your post to add CODE tags.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    04-23-2014
    Location
    Delhi
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Error with distribution code

    Hi PCI,
    Thanks for your quick reply.

    I added the "End If", but still gettin error.Since I have basic knowlede of VBA, I will sincely appreciate if you could help me fix the error. My code after adding "End If' is given below. In addition, I have also added the screenshot of the new error I am getting.

    Please Login or Register  to view this content.
    Error-1.jpg

    Thanks,
    Nisha

  5. #5
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Error with distribution code

    It will easier to have a sample of your file.
    Use the Option explicit at the beginning of your code
    Use myCell every where not myCel
    Last edited by PCI; 05-06-2014 at 04:20 PM. Reason: Typo

  6. #6
    Registered User
    Join Date
    04-23-2014
    Location
    Delhi
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Error with distribution code

    Hi PCI,

    I tried the option you suggested, but unfortunotelly it is not working. Also, I was not getting any optionn to attach file in this post, hence I have started new post with file attached. I hope it will be helpful for you to help me resolve the issue.

    Thanks a lot for your effort and time.
    Nisha

  7. #7
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Error with distribution code

    Nisha,
    To attach a file:
    Go Advanced
    Manage Attachments
    Add Files
    Basic Uploader
    Browse
    ==> select your file
    Upload
    ==> your file appear in the Attachments window)
    Done
    Did you watch the myCell variable every it is used: "myCel.Offset(, 3).Value)"

  8. #8
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,088

    Re: Error with distribution code

    Nisha,
    Reading your new thread you have understood :
    How it's easier to see the issue with a file attached
    The problem was coming from space with the letter "Y"
    The Trim function is removing these spaces
    See
    http://www.excelforum.com/excel-prog...tion-code.html

+ 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. vba code to generate random z-scores for normal distribution
    By bruceday in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-30-2012, 02:07 PM
  2. Replies: 3
    Last Post: 08-05-2012, 05:47 PM
  3. Code to create PDF, attach to email and send to distribution list
    By tim_chisman in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-18-2010, 09:08 AM
  4. VBA Code for a Distribution
    By moroformat in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-13-2009, 08:32 PM
  5. tips for organizing code for distribution
    By Eric in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-29-2005, 06:05 PM

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