help in macro_newbie

Mabangiz32

New Member
Joined
Mar 28, 2018
Messages
4
this is from the macro that i am using for optimization.
need help because when i start the macro it would count 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12 and so on.
i cannot find out how number 10 is not showing,

thanks for the help.

*macro

'Stampanje oznake sipke npr.A, B, C...itd.
slova = "123456789"
Range("f14").Value = "Bar"
Dim rowCnt As Integer, cntLevel1 As Integer, cntLevel2 As Integer
rowCnt = 0
cntLevel1 = -1
cntLevel2 = -1
Dim id As String
For i = 0 To komada - 1
id = ""
If cntLevel2 > -1 Then id = id + Mid(slova, cntLevel2 + 1, 1)
If cntLevel1 > -1 Then id = id + Mid(slova, cntLevel1 + 1, 1)


ActiveCell.Offset(i, 4).Value = id + Mid(slova, rowCnt + 1, 1)
rowCnt = rowCnt + 1
If rowCnt >= 10 Then
cntLevel1 = cntLevel1 + 1
rowCnt = 0
If cntLevel1 >= 10 Then
cntLevel2 = cntLevel2 + 1
cntLevel1 = 0
End If
End If
Next i


thanks for the help..
 

Some videos you may like

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,486
Office Version
  1. 365
Platform
  1. Windows
Welcome to the Board!

need help because when i start the macro it would count 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12 and so on.
i cannot find out how number 10 is not showing,

I have no idea what you macro is supposed to be doing (you haven't explained that part), but I do notice one thing.
It seems that it is looping through this string of numbers:
Code:
[COLOR=#333333]slova = "123456789"[/COLOR]
Notice that "0" is not in that string, and the number "10" has a 0 in it.
So I suspect that has something to do with it.
 

Mabangiz32

New Member
Joined
Mar 28, 2018
Messages
4
yes, you are correct, my problem is the looping.
number 10 is not showing and when it reach 19 20 would not show.

1.
2.
3.
4.
5.
6.
7.
8.
9.

11.
12.
13.
and so on.

can't figure what i am missing.

thank you for helping me out.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,486
Office Version
  1. 365
Platform
  1. Windows
can't figure what i am missing.
I mentioned what I think the problem is.
What happens if you change:
Code:
[COLOR=#333333]slova = "123456789"[/COLOR]
to
Code:
[COLOR=#333333]slova = "1234567890"[/COLOR]

If that does not fix it, please post the rest of the code associated with this.
I think you have left information off, as you are using a variable named "komada" that is not declared or set anywhere in the code you posted.
 

Mabangiz32

New Member
Joined
Mar 28, 2018
Messages
4
i am back, sorry about yesterday.

this is what i did as per your instruction.

slova = "1234567890"
Range("f14").Value = "Bar"
Dim rowCnt As Integer, cntLevel1 As Integer, cntLevel2 As Integer
rowCnt = 0
cntLevel1 = -1
cntLevel2 = -1
Dim id As String
For i = 0 To komada - 1
id = ""
If cntLevel2 > -1 Then id = id + Mid(slova, cntLevel2 + 1, 1)
If cntLevel1 > -1 Then id = id + Mid(slova, cntLevel1 + 1, 1)


ActiveCell.Offset(i, 4).Value = id + Mid(slova, rowCnt + 1, 1)
rowCnt = rowCnt + 1
If rowCnt >= 10 Then
cntLevel1 = cntLevel1 + 1
rowCnt = 0
If cntLevel1 >= 10 Then
cntLevel2 = cntLevel2 + 1
cntLevel1 = 0
End If
End If
Next i


and this what it displayed in my sheet.



Bar SumWaste
12460x11660x11060x1660x15840160
22460x11660x11060x1660x15840160
32460x11660x11060x1660x15840160
42460x11660x11060x1660x15840160
52460x2660x1 5580420
62460x2660x1 5580420
72460x2660x1 5580420
82460x2660x1 5580420
92460x2660x1 5580420
02460x2660x15580420
112460x2660x1 5580420
122460x2660x1 5580420
132460x2 49201080
142460x11660x1 41201880
151660x3 49801020
161660x3 49801020
172460x11660x2 5780220
182460x11660x2 5780220
191260x31060x2 5900100
101260x31060x25900100
211260x31060x2 5900100
221260x31060x2 5900100

<colgroup><col><col><col span="2"><col><col span="2"></colgroup><tbody>
</tbody>



you will notice that the number in the Bars are not corresponding accordingly. 0 and 10.
cant figure it out.

thank you for your patience..
 

Mabangiz32

New Member
Joined
Mar 28, 2018
Messages
4
basically, the problem is the sequence of the numbers which i cannot figure it out.
Bar
1
2
3
4
5
6
7
8
9
10
11
and so forth...
 

Watch MrExcel Video

Forum statistics

Threads
1,109,335
Messages
5,528,096
Members
409,802
Latest member
joeino

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top