Populate data in specific columns based on criteria - VBA

sidt87

New Member
Joined
Mar 1, 2017
Messages
16
Hi,

I am a creating an inventory database with about 100+ items. I am using a userform to select the ITEM PART via combobox, PO# via textbox and QUANTITY via textbox then enter it into my inventory database. What I would like it to do is search for the item number that was selected in the combobox in columns A1:AA1, then find the last empty row in that column and input the PO number and quantity.

My inventory database looks something like this, where as row 1 is the ITEM PARTS

ABCDEFGHI
1Item1Item2Item3Item4Item5Item6Item7Item8Item9
2
3
4

<tbody>
</tbody>


What I would like it to do is if I select and enter the following

ITEM PART: Item5
PO#: 12345
QUANTITY: 1000

it would find the column with Item5 and populate as below


ABCDEFGHI
1Item1Item2Item3Item4Item5Item6Item7Item8Item9
2PO# 12345
31000
4

<tbody>
</tbody>


Any help is much appreciated!

Thanks!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Perhaps this will help you get started.
Code:
Dim Res As Variant

    Res = Application.Match(cmbItems.Value, Rows(1), 0)

    If Not IsError(Res) Then
        Cells(Rows.Count).End(xlUp).Offset(,1).Resize(2).Value =Application.Transpose(Array(txtPONo.Value, txtQuantity.Value))
    End If
 
Upvote 0
Alright, so here's what I ended up doing

Code:
Private Sub CommandButton1_Click()


Dim ws As Worksheet
Dim iRow As Long
Dim Lastrow As Long
Dim Found As Range


Set ws = Worksheets("Inventory Log")


Lastrow = ws.Range("C:WD").Find("*", , , , xlByRows, xlPrevious).Row


If Me.itemnumber.Value = "" Then
    MsgBox "select item number please"
    Else
        Set Found = ws.Range("C:WD").Find(What:=Me.itemnumber.Value, _
                                                       LookIn:=xlValues, _
                                                       LookAt:=xlWhole, _
                                                       SearchOrder:=xlByColumns, _
                                                       SearchDirection:=xlNext, _
                                                       MatchCase:=False)
                                                       
        If Found Is Nothing Then
                MsgBox "Not Found"
        Else
            For iRow = 15 To Lastrow
                ws.Cells(iRow, Found.Column).Value = Me.ponumber.Value
                ws.Cells(iRow, Found.Column).Offset(1, 0).Value = Me.quantity.Value
            Next iRow
        End If
 End If
 
With ws
.Cells(iRow, Found.Column).Value = "PO#:" & "" & Me.ponumber.Value
.Cells(iRow, Found.Column).Offset(1, 0).Value = Me.quantity.Value
End With




End Sub

My first entry turns out ok but when I do a second entry, it populates into the same cells plus into the next two cells its suppose to. Any idea how to fix this?

Thanks!
 
Upvote 0
Is it me or do you have the code doing the same thing twice here? Correct me if I'm wrong please:

Code:
 For iRow = 15 To Lastrow
                ws.Cells(iRow, Found.Column).Value = Me.ponumber.Value
                ws.Cells(iRow, Found.Column).Offset(1, 0).Value = Me.quantity.Value
            Next iRow

With ws
.Cells(iRow, Found.Column).Value = "PO#:" & "" & Me.ponumber.Value
.Cells(iRow, Found.Column).Offset(1, 0).Value = Me.quantity.Value
End With

Sorry that's not a solution I know, I'm just trying to understand as much as I can on this site today.
 
Upvote 0
Is it me or do you have the code doing the same thing twice here? Correct me if I'm wrong please:

Code:
 For iRow = 15 To Lastrow
                ws.Cells(iRow, Found.Column).Value = Me.ponumber.Value
                ws.Cells(iRow, Found.Column).Offset(1, 0).Value = Me.quantity.Value
            Next iRow

With ws
.Cells(iRow, Found.Column).Value = "PO#:" & "" & Me.ponumber.Value
.Cells(iRow, Found.Column).Offset(1, 0).Value = Me.quantity.Value
End With

Sorry that's not a solution I know, I'm just trying to understand as much as I can on this site today.

I'm still a noob myself, but from what I understand whenever I use For and Next, I have to follow it with With and End With in order for the data to actually input. Maybe someone else can chime in on your question.
 
Upvote 0

Forum statistics

Threads
1,214,661
Messages
6,120,790
Members
448,994
Latest member
rohitsomani

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