Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
  • Avatar do usuário
#17739
Galera! blz?

Sou novo no VBA, preciso de um Help!!
Não estou conseguindo usar variáveis como parâmetros de funções, como faço isso?

Por exemplo:
ActiveCell.FormulaR1C1 = "=GetKM(variavel,-32,RC[-5],RC[-4])"

onde tem variável, não consigo coloca-la, da erro!!
tentei colocar cells(l,c), tbm não funciona!
por ex:
ActiveCell.FormulaR1C1 = "=GetKM(cells(l,c),-32,RC[-5],RC[-4])"

Abaixo está o código

'calcula as distancias de todos
Sub calcula_distancia_todos()
Dim lin1, lin2 As Integer

' quantidade de linhas da mesma equipe
lin1 = 2 'primeira ocorrencia
lin2 = 2 ' ultima ocorrencia
latit = 0
longit = 0

Do While Cells(lin1, 47).Value = Cells(lin2, 47).Value
latit = Cells(lin1, 64).Value
longit = Cells(lin1, 65).Value

'qtdLinhas = qtdLinhas + 1
Cells(lin2 + 1, 69).Select
ActiveCell.FormulaR1C1 = "=GetKM(latit,longit,RC[-5],RC[-4])"
lin2 = lin2 + 1

Loop
' lin1 = lin2
End Sub


'Distancia Linear entre dois pontos
Function GetKM(lat1Degrees As Double, lon1Degrees As Double, lat2Degrees As Double, lon2Degrees As Double)
Dim earthSphereRadiusKilometers As Double
Dim kilometerConversionToMilesFactor As Double
Dim lat1Radians As Double
Dim lon1Radians As Double
Dim lat2Radians As Double
Dim lon2Radians As Double
Dim AsinBase As Double
Dim DerivedAsin As Double
'Mean radius of the earth (replace with 3443.89849 to get nautical miles)
earthSphereRadiusKilometers = 6371
'Convert kilometers into miles
kilometerConversionToMilesFactor = 0.621371
'Convert each decimal degree to radians
lat1Radians = (lat1Degrees / 180) * 3.14159265359
lon1Radians = (lon1Degrees / 180) * 3.14159265359
lat2Radians = (lat2Degrees / 180) * 3.14159265359
lon2Radians = (lon2Degrees / 180) * 3.14159265359
AsinBase = Sin(Sqr(Sin((lat1Radians - lat2Radians) / 2) ^ 2 + Cos(lat1Radians) * Cos(lat2Radians) * Sin((lon1Radians - lon2Radians) / 2) ^ 2))
DerivedAsin = (AsinBase / Sqr(-AsinBase * AsinBase + 1))
'Get distance from [lat1,lon1] to [lat2,lon2]
GetKM = Round(2 * DerivedAsin * earthSphereRadiusKilometers, 2)
'Miles: = Round(2 * DerivedAsin * (earthSphereRadiusKilometers * kilometerConversionToMilesFactor), 2)
End Function

O problema está nas variáveis latit e longit, tentei de varias formas, não consegui!

Alguem pode me ajudar! pfv!!
oseas
Membro
Membro

Mensagens: 4
Registrado em: Seg Nov 28, 2016 3:39 pm
Has thanked: 0 time
Have thanks: 0 time
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord