Prompt Details
Model
Chat - GPT-4 (gpt-4)
Token size
596 ($0.01790 / call)
Example input
I am looking to build a macro that checks all the numbers in a table, and if there are any prime numbers, multiply them together and give me the result
Example output
Here's the VBA code that implements the defined logic:
Sub MultiplyPrimeNumbers()
Dim rng As Range
Dim cell As Range
Dim product As Double
Set rng = Range("A1:D12")
product = 1
For Each cell In rng
If IsNumeric(cell.Value) And cell.Value > 1 Then
If IsPrime(cell.Value) Then
product = product * cell.Value
End If
End If
Next cell
Range("E20").Value = product
End Sub
Function IsPrime(number As Double) As Boolean
Dim i As Double
For i = 2 To Sqr(number)
If number Mod i = 0 Then
IsPrime = False
Exit Function
End If
Next i
IsPrime = True
End Function
By purchasing this prompt, you agree to our terms of service
GPT-4
This prompt specializes in automating tasks ranging from basic data entry to complex calculations.
You'll be guided through a structured process that involves defining your macro task, creating a logical sequence of steps, coding the macro in VBA, testing, debugging, and documenting the macro's functionality. This approach ensures that the macro accomplishes your intended task accurately and efficiently.
...more
Added over 1 month ago

