Reputation: 901
Okay, so I'm trying to create an order log for a business (employee usage).
I have a form set out where multiple users can access/input all the information needed. It prints into an Excel spreadsheet for one person to open and place orders from. Sometimes a user might want to copy an order line from a previous year's log (there are 4 so far), so I'm trying to incorporate that into the current log.
I'm having trouble with referencing another workbook that the user has opened and copying the information into a userform opened in the current log. I have this:
Private Sub cmdCopy_Click()
Dim rowRef As Integer, colItem As Integer, colSup As Integer, colCatNum As Integer, colQty As Integer, colUnit As Integer, colCat As Integer
'stores row of selected order from old order log successfully
rowRef = ActiveCell.row
'I'm trying to find which column has which headers as the logs aren't consistent
For x = 2 To 9
If ActiveWorkbook.Sheet1.Cells(2, x).Text = "Item" Then
colItem = x
ElseIf ActiveWorkbook.Sheet1.Cells(2, x).Text = "Supplier" Then
colSup = x
ElseIf ActiveWorkbook.Sheet1.Cells(2, x).Text = "Catalogue #" Then
colCatNum = x
ElseIf ActiveWorkbook.Sheet1.Cells(2, x).Text = "Qty" Then
colQty = x
ElseIf ActiveWorkbook.Sheet1.Cells(2, x).Text = "Unit" Then
colUnit = x
ElseIf ActiveWorkbook.Sheet1.Cells(2, x).Text = "Category" Then
colCat = x
End If
Next x
'fills information into userform
txtItem.Text = Sheet1.Cells(rowRef, colItem).Text
txtSup.Text = Sheet1.Cells(rowRef, colSup).Value
txtCatNum.Text = Sheet1.Cells(rowRef, colCatNum).Value
txtQty.Text = Sheet1.Cells(rowRef, colQty).Value
cboUnit.Text = Sheet1.Cells(rowRef, colUnit).Value
cboCat.Text = Sheet1.Cells(rowRef, colCat).Value
End Sub
So what I want to happen is:
If there is any requirement for clarification, let me know. I'm sorry if this is in the forums already, but using my search terms I could not find answers that helped.
Upvotes: 0
Views: 448
Reputation: 3136
Seems like a simple syntax issue to me:
you want to change:
If ActiveWorkbook.Sheet1.Cells(2, x).Text = "Item" Then
To:
If ActiveWorkbook.Sheets(1).Cells(2, x).Text = "Item" Then
The Sheet1 syntax didn't work for me.
And obviously you want to make the same change wherever else Sheet1 occurs.
Upvotes: 1