Inputting Items and Descriptions into database

Jetx227

Board Regular
Joined
Jul 11, 2018
Messages
96
Hey guys! You have been a big help so far but I got another question (not surprisingly).
So I have this worksheet that has a database of about 20,000 items and on occasion we will have to input new ones. The items are organized by item number (column A) in numerical order. They also have a bunch of different values associated to them (columns B through L) but the most important ones are item number (column A), units (column E) and description (column L). We want to put in a row on top of the list (input in row 2, list would start at 7, headers at 5) where we can fill in the 3 main pieces we need filled out, item number (column A), units (column E) and description (column L), click a button, and have it automatically create a new row (based on numerical order) and input the values we entered. If there's a way for it to double check and see if the item already exists (so we don't add duplicates by mistake), that would be awesome, but its not necessary. Also we need column A to be formatted as text (even though we are inputting numbers). Any help you guys can offer would be much appreciated, thanks!
 
Last edited:
This should fix your problem - no need to enter A2 with an apostrophe now, but if you do that's ok too.
Code:
Sub Button1_Click()
Dim lR As Long, Inp As Range, n As Variant, R As Range, c As Range
lR = Range("A" & Rows.Count).End(xlUp).Row
Set Inp = Range("A2:L2")
If IsEmpty(Range("A2")) Then
    MsgBox "Please enter an Item # in A2 - then try again"
    Exit Sub
End If
n = Application.CountIf(Range("A7:A" & lR), Range("A2").Value)
If n > 0 Then
    MsgBox "The Item# you entered in A2 is already in the database"
    Exit Sub
End If
Application.ScreenUpdating = False
With Range("A" & lR + 1, "L" & lR + 1)
    .Cells(1, 1).NumberFormat = "@"
    .Value = Inp.Value
End With
Set R = Range("A7").CurrentRegion
Columns(1).Insert
For Each c In R.Columns(1).Offset(0, -1).Cells
    c.Value = Val(c.Offset(0, 1))
Next c
Range("A7").CurrentRegion.Sort key1:=Range("A7"), order1:=xlAscending
Columns(1).Delete
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
This should fix your problem - no need to enter A2 with an apostrophe now, but if you do that's ok too.
Code:
Sub Button1_Click()
Dim lR As Long, Inp As Range, n As Variant, R As Range, c As Range
lR = Range("A" & Rows.Count).End(xlUp).Row
Set Inp = Range("A2:L2")
If IsEmpty(Range("A2")) Then
    MsgBox "Please enter an Item # in A2 - then try again"
    Exit Sub
End If
n = Application.CountIf(Range("A7:A" & lR), Range("A2").Value)
If n > 0 Then
    MsgBox "The Item# you entered in A2 is already in the database"
    Exit Sub
End If
Application.ScreenUpdating = False
With Range("A" & lR + 1, "L" & lR + 1)
    .Cells(1, 1).NumberFormat = "@"
    .Value = Inp.Value
End With
Set R = Range("A7").CurrentRegion
Columns(1).Insert
For Each c In R.Columns(1).Offset(0, -1).Cells
    c.Value = Val(c.Offset(0, 1))
Next c
Range("A7").CurrentRegion.Sort key1:=Range("A7"), order1:=xlAscending
Columns(1).Delete
Application.ScreenUpdating = True
End Sub

It did format the cell as text, but the green triangle that should pop up on the top left corner of the cell doesn't (and I need it to otherwise our other sheets won't update for some reason) unless I scroll down to the cell and click into it then out of it. Is there a way to make it so I don't have to do this?
 
Last edited:
Upvote 0
I figured it out, all I did was input

Code:
Range("A" & lR + 1).Value = "'" & Range("A" & lR + 1).Value

into the With statement.

Thanks for your help!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,893
Members
449,194
Latest member
JayEggleton

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