Hi Guys! I am very new here and this is my first post. I am good with excel but new to access thus be patient, please.
I have a code using in Excel already but now I need the same for Access so is there anyone can modify it for me? First let me explain how does it work and its function.
The code is:
Its function is simply when sheet1 looks like this:
Sheet1
A
1 2
2 4
it checks from low value to high value if value 'n' is divisible with both (2 and 4) or not. If it is divisible with one of them, it does nothing. If it is not divisible with none (I mean both), it pastes the value to the next empty cell (in this case A3). And continues to check next values by this method.
And finally it looks like this:
Sheet1
A
1 2
2 4
3 5
4 7
5 9
6 11
7 13
Now, what I expect from Access is just to do the same. First, I'll have two Record lines in the table. In a field name like, let's say "Division" field, there'll be 2 and 4. What I want is, make Access to do the same divisibility check and if it is not divisible with none of the above values, to make Access to insert a new Record line and put the value into the related field (Division).
That's all! Thanks for your help from very this moment!!
I have a code using in Excel already but now I need the same for Access so is there anyone can modify it for me? First let me explain how does it work and its function.
The code is:
Code:
Sub example()
Const nlow As Long = 5
Const nHigh As Long = 13
Dim oRng As Range
Dim vArr() As Variant
Dim v As Variant
Dim Dict As Object
Dim n As Long
Dim i As Long
Dim j As Long
Set oRng = Range("A1", Cells(Rows.Count, "A").End(xlUp))
Set Dict = CreateObject("scripting.dictionary")
With Application
vArr = .Transpose(oRng.Value2)
For i = 1 To UBound(vArr)
Dict.Add Key:=vArr(i), Item:=vArr(i)
Next i
i = Dict.Count
For n = nlow To nHigh
j = 0
For Each v In Dict
If (n Mod v) > 0 Then
j = j + 1
Else
Exit For
End If
Next v
If j = i Then
Dict.Add Key:=n, Item:=n
i = i + 1
End If
Next n
oRng.Resize(i, 1) = .Transpose(Dict.Items)
End With
End Sub
Its function is simply when sheet1 looks like this:
Sheet1
A
1 2
2 4
it checks from low value to high value if value 'n' is divisible with both (2 and 4) or not. If it is divisible with one of them, it does nothing. If it is not divisible with none (I mean both), it pastes the value to the next empty cell (in this case A3). And continues to check next values by this method.
And finally it looks like this:
Sheet1
A
1 2
2 4
3 5
4 7
5 9
6 11
7 13
Now, what I expect from Access is just to do the same. First, I'll have two Record lines in the table. In a field name like, let's say "Division" field, there'll be 2 and 4. What I want is, make Access to do the same divisibility check and if it is not divisible with none of the above values, to make Access to insert a new Record line and put the value into the related field (Division).
That's all! Thanks for your help from very this moment!!
Last edited: