Unexpected behavior in VBA code

MyGiG

New Member
Joined
Mar 17, 2016
Messages
10
Hello, I've written some code that converts 1500 data points to about 200 (copies every 20th data point to the right), since Exel can't use more than 250 to draw a graph. So the wird part is, if I use the code below, everything works fine, but if I devide the result by 10, I get "0" in the fields.
shrani.si
[/URL][/IMG]
Sub Gumb_graf()


navpicno = 2
navpicnoBrezPreskoka = 2
obmocjePolnihCelic = 2

'prešteje polne celice leve tabele
Do While Worksheets("List1").Cells(navpicnoBrezPreskoka, 1) <> ""
obmocjePolnihCelic = obmocjePolnihCelic + 1
navpicnoBrezPreskoka = navpicnoBrezPreskoka + 1
Loop

'določanje celic, katere se bodo zajele
vsakiKolikiPodatek = Round(obmocjePolnihCelic / Worksheets("1").Cells(16, 16), 0)

navpicnoBrezPreskoka = 2

'praznjenje desne tabele, da se ne prekriva
Do While Worksheets("List1").Cells(navpicnoBrezPreskoka, 16) <> ""
Worksheets("List1").Cells(navpicnoBrezPreskoka, 16) = ""
Worksheets("List1").Cells(navpicnoBrezPreskoka, 17) = ""
Worksheets("List1").Cells(navpicnoBrezPreskoka, 18) = ""
Worksheets("List1").Cells(navpicnoBrezPreskoka, 19) = ""
navpicnoBrezPreskoka = navpicnoBrezPreskoka + 1
Loop

navpicnoBrezPreskoka = 2
navpicno = 2

Do While Worksheets("List1").Cells(navpicnoBrezPreskoka, 1) <> ""
Worksheets("List1").Cells(navpicnoBrezPreskoka, 16) = Worksheets("List1").Cells(navpicno, 5)
Worksheets("List1").Cells(navpicnoBrezPreskoka, 17) = Worksheets("List1").Cells(navpicno, 2)
Worksheets("List1").Cells(navpicnoBrezPreskoka, 18) = Worksheets("List1").Cells(navpicno, 3)
Worksheets("List1").Cells(navpicnoBrezPreskoka, 19) = Worksheets("List1").Cells(navpicno, 4)
navpicno = navpicno + vsakiKolikiPodatek
navpicnoBrezPreskoka = navpicnoBrezPreskoka + 1
Loop


End Sub

Now, if i devide the result by 10 (code below) I get zeros at the end

Sub Gumb_graf()


navpicno = 2
navpicnoBrezPreskoka = 2
obmocjePolnihCelic = 2

'prešteje polne celice leve tabele
Do While Worksheets("List1").Cells(navpicnoBrezPreskoka, 1) <> ""
obmocjePolnihCelic = obmocjePolnihCelic + 1
navpicnoBrezPreskoka = navpicnoBrezPreskoka + 1
Loop

'določanje celic, katere se bodo zajele
vsakiKolikiPodatek = Round(obmocjePolnihCelic / Worksheets("1").Cells(16, 16), 0)

navpicnoBrezPreskoka = 2

'praznjenje desne tabele, da se ne prekriva
Do While Worksheets("List1").Cells(navpicnoBrezPreskoka, 16) <> ""
Worksheets("List1").Cells(navpicnoBrezPreskoka, 16) = ""
Worksheets("List1").Cells(navpicnoBrezPreskoka, 17) = ""
Worksheets("List1").Cells(navpicnoBrezPreskoka, 18) = ""
Worksheets("List1").Cells(navpicnoBrezPreskoka, 19) = ""
navpicnoBrezPreskoka = navpicnoBrezPreskoka + 1
Loop

navpicnoBrezPreskoka = 2
navpicno = 2

Do While Worksheets("List1").Cells(navpicnoBrezPreskoka, 1) <> ""
Worksheets("List1").Cells(navpicnoBrezPreskoka, 16) = Worksheets("List1").Cells(navpicno, 5)
Worksheets("List1").Cells(navpicnoBrezPreskoka, 17) = Worksheets("List1").Cells(navpicno, 2) / 10
Worksheets("List1").Cells(navpicnoBrezPreskoka, 18) = Worksheets("List1").Cells(navpicno, 3) / 10
Worksheets("List1").Cells(navpicnoBrezPreskoka, 19) = Worksheets("List1").Cells(navpicno, 4) / 10
navpicno = navpicno + vsakiKolikiPodatek
navpicnoBrezPreskoka = navpicnoBrezPreskoka + 1
Loop


End Sub
shrani.si
[/URL][/IMG]

Does anyone know why this happens?
 
So I've tried it and it clearly shows, that there is something from with my loop. Just have to figure out what :D Thank you very much for helping me out!
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top