I'm trying to configure data in a very specific format in order for it to be uploaded to a software.
I have a count sheet that has the amount of lines needed to be entered on my upload template sheet. The values on the count sheet range between 3, 5, 7, and 9.
I want my VBA program to be able to enter values 1, 2, 3, (on 3 separate rows) on the upload template sheet if the value is "3" on the count sheet.
If the next value is "5" on the count sheet I want my program to be able to enter values 1, 2, 3, 2, 3 (on 5 separate rows on the upload sheet).
If a value is "9" on the count sheet, I want my program to enter values 1, 2, 3, 2, 3, 2, 3, 2, 3 (on 9 separate rows) and so on.
The first three values will always be 1, 2, 3, consecutively and then alternating between 2 and 3 based on the value on the count sheet.
Can anyone help me out here?
There aren't enough details to really write anything. But here's a tutorial/example of how to access data from seperate workbooks and how to write values into cells inside a loop.
The equation you were looking for where the output row # follows the pattern
1,2,3,2,3,2,3...is a little complicated with normal math, but it can be accomplished in programming math by using a Boolean expression as part of the equation.To explain the formula:
i Mod 2 - 2 * (i > 1)i Mod 2is taking the iterating valueiand retrieving the remainder after dividing by 2. This alternates between 1 and 0.We would just need
+2in order to move that from1 and 0to3 and 2. But we only want+2after the first number since we want the first number to be 1.So I added the boolean expression
(i > 1)which is 0 when False and -1 when True. I don't know why True = -1 in VBA. So the term- 2 * (i > 1)is 0 wheni = 1and+2wheni > 1.