Loop values upto three decimal places within a cell
Dim j As Long
Dim mycell As Range
For j = 0 To 24
Range("C12").Value = j
Range("C93").Formula = "=Round(Sin(C12*pi()/180)*(C84+C88),3)"
Range("C94").Formula = "=Round((Sin(C12*pi()/180)*(C84+C88))/1000,2)"
Range("C96").Formula = "=Round(-1*(C80-C93),3)"
Range("C98").Formula = "=Round((-1*(C80-C93))/1000,2)"
If Range("C94").Value = Range("C82").Value Then
MsgBox "The Maximum value of Theta is " & Range("C12").Value & Chr(10)
Exit For
End If
Next
I follow a code that loops j from 0 to 24. Example: 0,1,2,....24.
But how do I loop from values 0.001 to 0.999, then 1.101.....till 24.
How do I loop up to the desired decimal places?
excel vba excel-vba
add a comment |
Dim j As Long
Dim mycell As Range
For j = 0 To 24
Range("C12").Value = j
Range("C93").Formula = "=Round(Sin(C12*pi()/180)*(C84+C88),3)"
Range("C94").Formula = "=Round((Sin(C12*pi()/180)*(C84+C88))/1000,2)"
Range("C96").Formula = "=Round(-1*(C80-C93),3)"
Range("C98").Formula = "=Round((-1*(C80-C93))/1000,2)"
If Range("C94").Value = Range("C82").Value Then
MsgBox "The Maximum value of Theta is " & Range("C12").Value & Chr(10)
Exit For
End If
Next
I follow a code that loops j from 0 to 24. Example: 0,1,2,....24.
But how do I loop from values 0.001 to 0.999, then 1.101.....till 24.
How do I loop up to the desired decimal places?
excel vba excel-vba
add a comment |
Dim j As Long
Dim mycell As Range
For j = 0 To 24
Range("C12").Value = j
Range("C93").Formula = "=Round(Sin(C12*pi()/180)*(C84+C88),3)"
Range("C94").Formula = "=Round((Sin(C12*pi()/180)*(C84+C88))/1000,2)"
Range("C96").Formula = "=Round(-1*(C80-C93),3)"
Range("C98").Formula = "=Round((-1*(C80-C93))/1000,2)"
If Range("C94").Value = Range("C82").Value Then
MsgBox "The Maximum value of Theta is " & Range("C12").Value & Chr(10)
Exit For
End If
Next
I follow a code that loops j from 0 to 24. Example: 0,1,2,....24.
But how do I loop from values 0.001 to 0.999, then 1.101.....till 24.
How do I loop up to the desired decimal places?
excel vba excel-vba
Dim j As Long
Dim mycell As Range
For j = 0 To 24
Range("C12").Value = j
Range("C93").Formula = "=Round(Sin(C12*pi()/180)*(C84+C88),3)"
Range("C94").Formula = "=Round((Sin(C12*pi()/180)*(C84+C88))/1000,2)"
Range("C96").Formula = "=Round(-1*(C80-C93),3)"
Range("C98").Formula = "=Round((-1*(C80-C93))/1000,2)"
If Range("C94").Value = Range("C82").Value Then
MsgBox "The Maximum value of Theta is " & Range("C12").Value & Chr(10)
Exit For
End If
Next
I follow a code that loops j from 0 to 24. Example: 0,1,2,....24.
But how do I loop from values 0.001 to 0.999, then 1.101.....till 24.
How do I loop up to the desired decimal places?
excel vba excel-vba
excel vba excel-vba
edited Nov 12 '18 at 14:08
Pᴇʜ
20.9k42650
20.9k42650
asked Nov 12 '18 at 13:42
VOMVOM
184
184
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Maybe something like this:
Sub Test()
Dim j As Long, k As Long
For k = 0 To 24
For j = 1 To 999
Debug.Print k + (j / 1000)
Next j
Next k
End Sub
add a comment |
You can create an inner loop with something like
For j = 0 To 24
Dim d As Double
For d = 0 To 0.999 Step 0.001
Range("C12").Value = j + d
...
Next d
Next j
add a comment |
The idea here is to keep the looping simple and exclude unneeded values inside the loop:
Public Sub Test()
Dim j As Double
For j = 0.001 To 24 Step 0.001
If j < 1 Or j > 1.1 Then
Debug.Print Format(j, "0.000")
End If
Next
End Sub
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53263465%2floop-values-upto-three-decimal-places-within-a-cell%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Maybe something like this:
Sub Test()
Dim j As Long, k As Long
For k = 0 To 24
For j = 1 To 999
Debug.Print k + (j / 1000)
Next j
Next k
End Sub
add a comment |
Maybe something like this:
Sub Test()
Dim j As Long, k As Long
For k = 0 To 24
For j = 1 To 999
Debug.Print k + (j / 1000)
Next j
Next k
End Sub
add a comment |
Maybe something like this:
Sub Test()
Dim j As Long, k As Long
For k = 0 To 24
For j = 1 To 999
Debug.Print k + (j / 1000)
Next j
Next k
End Sub
Maybe something like this:
Sub Test()
Dim j As Long, k As Long
For k = 0 To 24
For j = 1 To 999
Debug.Print k + (j / 1000)
Next j
Next k
End Sub
answered Nov 12 '18 at 13:56
Darren Bartrup-CookDarren Bartrup-Cook
13.9k11432
13.9k11432
add a comment |
add a comment |
You can create an inner loop with something like
For j = 0 To 24
Dim d As Double
For d = 0 To 0.999 Step 0.001
Range("C12").Value = j + d
...
Next d
Next j
add a comment |
You can create an inner loop with something like
For j = 0 To 24
Dim d As Double
For d = 0 To 0.999 Step 0.001
Range("C12").Value = j + d
...
Next d
Next j
add a comment |
You can create an inner loop with something like
For j = 0 To 24
Dim d As Double
For d = 0 To 0.999 Step 0.001
Range("C12").Value = j + d
...
Next d
Next j
You can create an inner loop with something like
For j = 0 To 24
Dim d As Double
For d = 0 To 0.999 Step 0.001
Range("C12").Value = j + d
...
Next d
Next j
answered Nov 12 '18 at 13:59
FunThomasFunThomas
4,6211523
4,6211523
add a comment |
add a comment |
The idea here is to keep the looping simple and exclude unneeded values inside the loop:
Public Sub Test()
Dim j As Double
For j = 0.001 To 24 Step 0.001
If j < 1 Or j > 1.1 Then
Debug.Print Format(j, "0.000")
End If
Next
End Sub
add a comment |
The idea here is to keep the looping simple and exclude unneeded values inside the loop:
Public Sub Test()
Dim j As Double
For j = 0.001 To 24 Step 0.001
If j < 1 Or j > 1.1 Then
Debug.Print Format(j, "0.000")
End If
Next
End Sub
add a comment |
The idea here is to keep the looping simple and exclude unneeded values inside the loop:
Public Sub Test()
Dim j As Double
For j = 0.001 To 24 Step 0.001
If j < 1 Or j > 1.1 Then
Debug.Print Format(j, "0.000")
End If
Next
End Sub
The idea here is to keep the looping simple and exclude unneeded values inside the loop:
Public Sub Test()
Dim j As Double
For j = 0.001 To 24 Step 0.001
If j < 1 Or j > 1.1 Then
Debug.Print Format(j, "0.000")
End If
Next
End Sub
edited Nov 12 '18 at 14:47
answered Nov 12 '18 at 14:06
Brian M StaffordBrian M Stafford
2,7491814
2,7491814
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53263465%2floop-values-upto-three-decimal-places-within-a-cell%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown