Advice for simple code please

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Morning,

I have a worksheet called POSTAGE
First row with data is row 8 then down the page.
Column G are dates BUT there are a few Text entries.

These text enteries are what i am interested in & are as follows.
RETURNED, LOST, UNKNOWN, COLLECTION, RECEIVED, NO DATE

I will make a userform where i can click a command button which will then specifically search for the text entry names mentioned in column G
These Text entries will then be shown in a list box on the userform.

Clicking on a Text Entry will then go to the cell in question at column G

If it helps all entries other then thos mentioned will be dates or N/A
 
I click the command button to open the form & i see the message.

Also when i click F5 in code editor i see it
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Is your ComboBox named ComboBox1, that's the only thing that I can see that would give that error.

If you put a break point at the Userform Show line and step through the code, that will show which line is causing the error.
 
Upvote 0
I see the spelling was shortened.
Now have it working so looking at both
 
Upvote 0
Code like this might do what you want
VBA Code:
Private Sub CommandButton1_Click()
    With ListBox1
        If .ListIndex <> -1 Then
            Application.Goto Range(ListBox1.List(ListBox1.ListIndex, 1))
        End If
    End With
End Sub

Private Sub CommandButton2_Click()
    Unload Me
End Sub

Private Sub UserForm_Initialize()
    Dim oneCell As Range
    ListBox1.ColumnCount = 2
    With ActiveSheet.Range("G:G")
        For Each oneCell In Range(.Cells(8, 1), .Cells(Rows.Count, 1).End(xlUp))
            If IsNumeric(Application.Match(oneCell.Value, Array("RETURNED", "LOST", "UNKNOWN", "COLLECTION", "RECEIVED", "NO DATE"), 0)) Then
                ListBox1.AddItem oneCell.Value
                ListBox1.List(ListBox1.ListCount - 1, 1) = oneCell.Address
            End If
        Next oneCell
    End With
End Sub


This is the item i have gone with.
Can you advise please how i edit that once i click the command button as opposed to going to the cell in column G it selects the row itself or the cell A of that row.
Reason being when it selects the G cell my work sheet all moves left & off the page.
 
Upvote 0
If you want the entire row

VBA Code:
Application.Goto Range(ListBox1.List(ListBox1.ListIndex, 1)).EntireRow

If you want the A column cell of that row

VBA Code:
Application.Goto Range(ListBox1.List(ListBox1.ListIndex, 1)).EntireRow.Range("A1")
 
Upvote 0

Forum statistics

Threads
1,215,235
Messages
6,123,784
Members
449,124
Latest member
shreyash11

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