回覆 10# s20012797


我覺得vba 好難被淘汰,好多銀行證券行或其它行業都用緊,積累左N 年,如果要轉,工程極大。

TOP

回覆 8# eddy

請問你用既數據量有幾多? 你的結果同我的認知有少少出入,估吾到index match 快過double vlookup

TOP

回覆  s20012797


我覺得vba 好難被淘汰,好多銀行證券行或其它行業都用緊,積累左N 年,如果要轉,工程 ...
bongbong3481 發表於 2023-11-6 12:07


條友唔識係度亂吹, 唔洗咁認真.

TOP

回覆  eddy

請問你用既數據量有幾多? 你的結果同我的認知有少少出入,估吾到index match 快過double vlo ...
bongbong3481 發表於 2023-11-6 12:21

Index match 同double vlookup 差唔多,只係後者要先做一次sorting 就麻煩少少

TOP

excel 下一版都吾知仲有冇得VBA,你同我講要記formula
s20012797 發表於 2023-11-6 10:06

未必咁多公司跟得咁貼用新版office , 而excel formula 係excel 一個重要核心,唔預期會消失吧…..

TOP

回覆  s20012797

我覺得vba 好難被淘汰,好多銀行證券行或其它行業都用緊,積累左N 年,如果要轉,工程 ...
bongbong3481 發表於 2023/11/6 12:07
未必咁多公司跟得咁貼用新版office , 而excel formula 係excel 一個重要核心,唔預期會消失吧….. ...
eddy 發表於 2023/11/6 15:14


無聊寫兩個code玩下


python

  1. from math import sin, acos, degrees, tan, pi
  2. from datetime import datetime, timedelta

  3. # Define a class to calculate sunrise and sunset times
  4. class SunriseSunsetCalculator:
  5.     # Earth's tilt angle
  6.     EARTH_TILT = 23.44
  7.     # Conversion factor from degrees to radians
  8.     TO_RADIANS = pi / 180

  9.     # Method to calculate solar declination
  10.     def calculate_declination(self, day_of_year):
  11.         return self.EARTH_TILT * sin(self.TO_RADIANS * ((360 / 365.0) * (day_of_year - 81)))

  12.     # Method to calculate hour angle
  13.     def calculate_hour_angle(self, latitude, declination):
  14.         return degrees(acos(-tan(latitude * self.TO_RADIANS) * tan(declination * self.TO_RADIANS)))

  15.     # Method to calculate sunrise and sunset times
  16.     def calculate(self, latitude, longitude):
  17.         # Check if latitude and longitude are within valid range
  18.         if not (-90 <= latitude <= 90) or not (-180 <= longitude <= 180):
  19.             raise ValueError("Invalid latitude or longitude value.")

  20.         # Get the current time
  21.         now = datetime.now()
  22.         # Get the current day of the year
  23.         day_of_year = (now - datetime(now.year, 1, 1)).days + 1

  24.         # Approximate calculation of solar declination
  25.         declination = self.calculate_declination(day_of_year)

  26.         # Calculate the hour angle
  27.         hour_angle = self.calculate_hour_angle(latitude, declination)

  28.         # Calculate sunrise and sunset times
  29.         solar_noon = datetime.combine(now.date(), datetime.min.time()) + timedelta(hours=12)
  30.         sunrise = solar_noon - timedelta(minutes=8 * hour_angle)
  31.         sunset = solar_noon + timedelta(minutes=8 * hour_angle)

  32.         return sunrise, sunset


  33. # Define a class to calculate the length of day and night in the Edo period
  34. class EdoPeriodClock:
  35.     # A day and a night in the Edo period each have 6 hours
  36.     HOURS_IN_EDO_DAY = 6
  37.     HOURS_IN_EDO_NIGHT = 6

  38.     # Method to calculate the length of day and night in the Edo period
  39.     def calculate(self, latitude, longitude):
  40.         # Calculate sunrise and sunset times
  41.         calculator = SunriseSunsetCalculator()
  42.         sunrise, sunset = calculator.calculate(latitude, longitude)

  43.         # Calculate the length of day and night
  44.         day_length = (sunset - sunrise).total_seconds() / 3600
  45.         night_length = 24 - day_length

  46.         # Calculate the length of day and night in the Edo period
  47.         edo_day_hour_length = day_length / self.HOURS_IN_EDO_DAY
  48.         edo_night_hour_length = night_length / self.HOURS_IN_EDO_NIGHT

  49.         return edo_day_hour_length, edo_night_hour_length


  50. # Example usage
  51. latitude = 37.7749  # Latitude of a location
  52. longitude = -122.4194  # Longitude of a location

  53. edo_clock = EdoPeriodClock()
  54. edo_day_hour_length, edo_night_hour_length = edo_clock.calculate(latitude, longitude)

  55. print(f"Length of Edo day hour: {edo_day_hour_length} hours")
  56. print(f"Length of Edo night hour: {edo_night_hour_length} hours")
複製代碼



VBA
  1. Option Explicit

  2. ' Define a class to calculate sunrise and sunset times
  3. Class SunriseSunsetCalculator
  4.     ' Earth's tilt angle
  5.     Private Const EARTH_TILT As Double = 23.44
  6.     ' Conversion factor from degrees to radians
  7.     Private Const TO_RADIANS As Double = 3.14159265358979 / 180

  8.     ' Method to calculate solar declination
  9.     Private Function CalculateDeclination(day_of_year As Integer) As Double
  10.         CalculateDeclination = EARTH_TILT * Sin(TO_RADIANS * ((360 / 365.0) * (day_of_year - 81)))
  11.     End Function

  12.     ' Method to calculate hour angle
  13.     Private Function CalculateHourAngle(latitude As Double, declination As Double) As Double
  14.         CalculateHourAngle = WorksheetFunction.Degrees(Acos(-Tan(latitude * TO_RADIANS) * Tan(declination * TO_RADIANS)))
  15.     End Function

  16.     ' Method to calculate sunrise and sunset times
  17.     Public Function Calculate(latitude As Double, longitude As Double) As Variant
  18.         ' Check if latitude and longitude are within valid range
  19.         If latitude < -90 Or latitude > 90 Or longitude < -180 Or longitude > 180 Then
  20.             Err.Raise Number:=5, Description:="Invalid latitude or longitude value."
  21.             Exit Function
  22.         End If

  23.         ' Get the current time
  24.         Dim now As Date
  25.         now = Now()
  26.         ' Get the current day of the year
  27.         Dim day_of_year As Integer
  28.         day_of_year = DateDiff("d", DateSerial(Year(now), 1, 0), now)

  29.         ' Approximate calculation of solar declination
  30.         Dim declination As Double
  31.         declination = CalculateDeclination(day_of_year)

  32.         ' Calculate the hour angle
  33.         Dim hour_angle As Double
  34.         On Error GoTo ErrorHandler
  35.         hour_angle = CalculateHourAngle(latitude, declination)
  36.         On Error GoTo 0

  37.         ' Calculate sunrise and sunset times
  38.         Dim solar_noon As Date
  39.         solar_noon = Date + TimeSerial(12, 0, 0)
  40.         Dim sunrise As Date
  41.         sunrise = solar_noon - TimeSerial(8 * hour_angle / 60, 0, 0)
  42.         Dim sunset As Date
  43.         sunset = solar_noon + TimeSerial(8 * hour_angle / 60, 0, 0)

  44.         Calculate = Array(sunrise, sunset)
  45.         Exit Function

  46. ErrorHandler:
  47.         Err.Raise Number:=Err.Number, Description:="Error calculating hour angle. " & Err.Description
  48.     End Function
  49. End Class

  50. ' Define a class to calculate the length of day and night in the Edo period
  51. Class EdoPeriodClock
  52.     ' A day and a night in the Edo period each have 6 hours
  53.     Private Const HOURS_IN_EDO_DAY As Integer = 6
  54.     Private Const HOURS_IN_EDO_NIGHT As Integer = 6

  55.     ' Method to calculate the length of day and night in the Edo period
  56.     Public Function Calculate(latitude As Double, longitude As Double) As Variant
  57.         ' Calculate sunrise and sunset times
  58.         Dim calculator As New SunriseSunsetCalculator
  59.         Dim sunrise_sunset As Variant
  60.         sunrise_sunset = calculator.Calculate(latitude, longitude)
  61.         Dim sunrise As Date
  62.         sunrise = sunrise_sunset(0)
  63.         Dim sunset As Date
  64.         sunset = sunrise_sunset(1)

  65.         ' Calculate the length of day and night
  66.         Dim day_length As Double
  67.         day_length = (sunset - sunrise) * 24
  68.         Dim night_length As Double
  69.         night_length = 24 - day_length

  70.         ' Calculate the length of day and night in the Edo period
  71.         Dim edo_day_hour_length As Double
  72.         edo_day_hour_length = day_length / HOURS_IN_EDO_DAY
  73.         Dim edo_night_hour_length As Double
  74.         edo_night_hour_length = night_length / HOURS_IN_EDO_NIGHT

  75.         Calculate = Array(edo_day_hour_length, edo_night_hour_length)
  76.     End Function
  77. End Class
複製代碼



純睇code&寫code而言,至少我吾覺得vba"仲適合學生(或初學)去學",至於"舊腳本"問題,買個Ai來重寫&捉蟲花吾上多少$,咁都比吾起學咩人做生意,就係咁

TOP

提示: 作者被禁止或刪除 內容自動屏蔽

TOP

有 excel 的 office,不是包埋 access ?

via HKEPC IR 5.1.14 - Android(5.1.2F)
波風水門 發表於 2023/11/7 11:45


冇記錯最平個Set得word,exceI,同PPT,
BTW,2023仍為非M$不可的,
系咪M$的office待別好打x機wwW

TOP

用Power Query

TOP

舊po 講double vlookup, 同你個case 差唔多
https://www.hkepc.com/forum/view ... =vlookup&page=1

TOP