PDA

View Full Version : Solved: Code Help



drums4monty
03-02-2008, 03:09 AM
Hi

I have a work book with 4 sheets, Uniform Retail, Stationary and Search which is a database of stock or my work. I want to use VLOOKUP to find items I want, which I can do, but I want to write some code to bring up an Input Box to ask what I want to search, Uniform, Retail or Stationary and then ask for the Item to search for. I have created this code but it does not work, I know very, very little about coding macros etc, but I am trying. Can anyone help?

Sub Database()

Dim sSheet As String
Dim sItem As String
sSheet = InputBox("Enter Section:")
Sheets("sSheet").Select
If [B3] = Empty Then
' Cancel = True
[B3].Activate
sItem = InputBox("Enter Item:")
[B3] = sItem
End If
End Sub

Kind regards

Alan

Bob Phillips
03-02-2008, 03:30 AM
Sub Database()
Dim sSheet As String
Dim sType As String
Dim sItem As String
Dim cell As Range

sType = InputBox("Enter U, R, or S for Uniform Retial, Retail or Stationary")
If sType <> "" Then

Select Case sType

Case "U": sSheet = "Uniform Retail"
Case "R": sSheet = "Retail"
Case "S": sSheet = "Stationary"
Case Else:
MsgBox "Invalid selection"
Exit Sub
End Select

sItem = InputBox("Enter item to search for")
If sType <> "" Then

With Sheets(sSheet)
Set cell = .Cells.Find(sItem)
If Not cell Is Nothing Then

Application.Goto cell
Else

MsgBox "Item not found"
End If
End With
End If
End If
End Sub

drums4monty
03-02-2008, 08:40 AM
Thanks xld, thats great. When I have found an Item, e.g. Mens P/T polo, there might be say 5 different sizes (these change, sometimes 4 sizes, 5 sizes, 6 sizes, but always called the same), is it possible to highlight all the same Items, e.g. search for Mens P/T polo and highlight all of these in the different sizes as a block. They are all listed together in the database alphabetically.

Bob Phillips
03-02-2008, 09:24 AM
Can you post a workbook for us to work on?

drums4monty
03-02-2008, 10:06 AM
I have messed about a bit and made the database all one one sheet, I was then able to write some code that did what I needed.

Thanks for all your help xld.

Regards

Alan