accessabel
New member
- Local time
- Yesterday, 22:20
- Joined
- Mar 24, 2014
- Messages
- 2
Hi,
my company ships items in packs of 20 and only tracks them as a lot or 20pack serial number. Well that serial number is say xxx00 which expands to xxx01, 02, 03... up to xxx19. I have an excel VBA script that will do this function for me (insert new row, add +1, repeat up to x times). But I would much prefer to do this in Access as that would allow me to finish automating the process which involves many other steps.
I do not know how to do much in VBA through access. I tried to create a Class Module with the following but it tells me "user-defined type not defined" and highlights the "SUB" line at the beginning. I have no idea what to do next! Can anyone help? In the code Test is the table I want to pull from and [Lot No] is the column header.
Sub FillSerials()
Dim rng As Range
Set rng = Range("Test.[Lot No]")
While rng.Value <> ""
rng.Offset(1).Resize(19).EntireRow.Insert
rng.Resize(, 1).Copy rng.Resize(20)
If TypeName(rng.Value) <> "String" Then
rng.Resize(20).DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
Step:=1, Trend:=False
Else
rng.AutoFill rng.Resize(20)
End If
Set rng = rng.Offset(20)
Wend
End Sub
my company ships items in packs of 20 and only tracks them as a lot or 20pack serial number. Well that serial number is say xxx00 which expands to xxx01, 02, 03... up to xxx19. I have an excel VBA script that will do this function for me (insert new row, add +1, repeat up to x times). But I would much prefer to do this in Access as that would allow me to finish automating the process which involves many other steps.
I do not know how to do much in VBA through access. I tried to create a Class Module with the following but it tells me "user-defined type not defined" and highlights the "SUB" line at the beginning. I have no idea what to do next! Can anyone help? In the code Test is the table I want to pull from and [Lot No] is the column header.
Sub FillSerials()
Dim rng As Range
Set rng = Range("Test.[Lot No]")
While rng.Value <> ""
rng.Offset(1).Resize(19).EntireRow.Insert
rng.Resize(, 1).Copy rng.Resize(20)
If TypeName(rng.Value) <> "String" Then
rng.Resize(20).DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
Step:=1, Trend:=False
Else
rng.AutoFill rng.Resize(20)
End If
Set rng = rng.Offset(20)
Wend
End Sub