PDA

View Full Version : Calculations using excel vba



hakunamatata
01-16-2013, 10:06 AM
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

Dave
01-16-2013, 09:06 PM
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

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

hakunamatata
01-17-2013, 12:08 AM
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.

Jan Karel Pieterse
01-17-2013, 12:49 AM
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.

hakunamatata
01-17-2013, 01:14 AM
Hello Jan,
Yes you are right. I never though about it.

Dave
01-17-2013, 09:15 AM
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

hakunamatata
01-17-2013, 10:44 AM
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.