Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Microsoft Office и VBA программирование > Microsoft Office Excel
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 01.02.2011, 16:28   #1
GRS1988
Пользователь
 
Регистрация: 10.02.2010
Сообщений: 18
По умолчанию Привет всем,связать мкрос с листом

Помогите кто может, огромное спасибо заранее...!

Вот код

Public Function socViplata(dateBegin As Date, dateEnd As Date, bebyNum As Integer) As Double
Dim i As Integer, j As Integer
Dim period
Dim summa As Double
Dim tmpDBEG As Date, tmpDEND As Date
Dim n As Byte ' количество периодов
If dateBegin > dateEnd Then socViplata = 1000000000: Exit Function
period = Array(#1/1/2007#, #1/1/2008#, #7/1/2008#, #1/1/2009#, #1/1/2010#)
tmpDBEG = dateBegin
summa = 0
n = 5

For i = n To 1 Step -1
If dateBegin >= period(i) Then
For j = i To n
If j = n Then
tmpDEND = dateEnd
summa = summa + Raschet(tmpDBEG, tmpDEND, bebyNum, j)
Exit For
End If
If dateEnd < period(j + 1) Then
tmpDEND = dateEnd
summa = summa + Raschet(tmpDBEG, tmpDEND, bebyNum, j)
Exit For
Else
tmpDEND = period(j + 1) - 1
summa = summa + Raschet(tmpDBEG, tmpDEND, bebyNum, j)
tmpDBEG = period(j + 1)
End If
Next j
Exit For
End If
Next i

socViplata = summa 'sum_1 + sum_2 + sum_3 + sum_4
End Function

Private Function Raschet(DBEG As Date, DEND As Date, beby_N As Integer, p As Integer) As Double
Dim dayToMon '(1 To 12) 'значения массива хранят количество дней в каждом из 12 месяцев
Dim plata As Double
Dim plataNum As Byte
Dim summa As Double, sumInDayBeg As Double, sumInDayEnd As Double
Dim indeks As Double
plataNum = Month(DEND) - Month(DBEG)
Select Case p
Case 1 '****** 01.01.2007 - 31.12.2007 ***************
dayToMon = Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
plata = 1500: indeks = 1
Case 2 '****** 01.01.2008 - 30.06.2008 ***************
dayToMon = Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
plata = 1500: indeks = 1.085
Case 3 '****** 01.07.2008 - 31.12.2008 ***************
dayToMon = Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
plata = 1627.5: indeks = 1.0185
Case 4 '****** 01.01.2009 - 31.12.2009 ***************
dayToMon = Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
plata = 1657.61: indeks = 1.13
Case 5 '****** 01.01.2010 - ??.??.20?? ***************
dayToMon = Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
plata = 1873.1: indeks = 1.1
End Select

sumInDayBeg = plata / dayToMon(Month(DBEG))
sumInDayEnd = plata / dayToMon(Month(DEND))
If plataNum = 0 Then
summa = sumInDayBeg * (Day(DEND) - Day(DBEG) + 1)
Else
summa = sumInDayBeg * (dayToMon(Month(DBEG)) - Day(DBEG) + 1) + _
plata * (plataNum - 1) + sumInDayEnd * Day(DEND)
End If

summa = summa * indeks
If beby_N > 1 Then summa = summa * 2
Raschet = Round(summa, 2)
End Function


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub




Excel в вложении...
Вложения
Тип файла: rar ШАБЛОН_22.12.2009.rar (14.2 Кб, 14 просмотров)
GRS1988 вне форума Ответить с цитированием
Старый 01.02.2011, 16:42   #2
Hugo121
Старожил
 
Регистрация: 11.05.2010
Сообщений: 5,166
По умолчанию

Непонятно...
так пробовали?
=socViplata(1/10/2010;1/10/2011;123)
webmoney: E265281470651 Z422237915069 R418926282008
Hugo121 вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Привет всем! ~Санёк~ Помощь студентам 2 07.03.2009 16:23
Не могу понять как надо ч/з форму вывести результат на лист и еще связать с другим листом данных Aliyushka Microsoft Office Excel 28 16.01.2009 19:44