Consulting

Results 1 to 7 of 7

Thread: Calculations using excel vba

  1. #1

    Calculations using excel vba

    Hello everybody.

    I want to calculate different values using excel vba. For the sake of example i have attached the excel file with this thread. Actually i need it badly.

    Thanks for your help to solve my problem.

    my sample code which does not works completely shown below.
    Sub Calculator()
            Dim Cover As Worksheet
            Set Cover = Worksheets("Sheet1")
            Cover.Activate
            
            With Cover
                iyear = Year(Range("F15")) & Month(Range("f5"))
                iyeartill = Year(Range("F16")) & Month(Range("f16"))
                imonth = Month(Range("f15"))
            End With
            
            With Sheets("sheet2").Activate
                For counter = iyear To iyeartill Step imonth
                 counter.Cells(69, 1) = "aa"
                Exit For
                Next counter
            End With
        
        End Sub
    Attached Files Attached Files
    Last edited by hakunamatata; 01-16-2013 at 10:36 AM.

  2. #2
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    835
    Location
    I have no idea what you're code is supposed to do? If you have sheets named sheet1, Year and Month which it seems you do, here's some untested code that may help get you started. Dave
    [vba]
    Sub Calculator()
    Dim Counter As Integer
    Dim Cover As Worksheet
    Set Cover = Worksheets("Sheet1")
    'this section makes no sense?
    With Cover
    iyear = Sheets("Year").Range("F15") + Sheets("Month").Range("f5")
    iyeartill = Sheets("Year").Range("F16") + Sheets("Month").Range("f16")
    imonth = Sheets("Month").Range("f15")
    End With
    With Sheets("sheet2")
    For Counter = iyear To iyeartill Step imonth
    .Cells(69, Counter) = "aa " & Counter
    'Exit For
    Next Counter
    End With
    End Sub

    [/vba]

  3. #3
    Hello
    Thanks alot for your help. Actually i have attached the sample workbook with this thread. Please try to generate the code according to the attached workbook. This code is not working according to the workbook.

  4. #4
    Just a quick note.

    I prefer people to write a description of their problem in the forum, rather than in an attached workbook. The search function of the forum is unable to search through attachments and hence your problem description is not searchable.
    Also, it takes me extra time to download and open the attachment as opposed to just reading your post.
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  5. #5
    Hello Jan,
    Yes you are right. I never though about it.

  6. #6
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    835
    Location
    Well... are you going to provide a description of what the code is supposed to do and what part of the code is "not working"? I really don't like messing with attached wbs. It seems like you have a "simple" syntax error (rather than a logic error) which likely can be easily resolved if we had some idea as to what the code is actually supposed to do. Dave

  7. #7
    Hello Again,
    I have changed the coding with the help of my friend. Now i just need the little changing in the code. Please find the attached file.
    Attached Files Attached Files

Posting Permissions

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