Insert row above cell with an exact value

lpking2005

Board Regular
Joined
Mar 21, 2011
Messages
140
hi, i have a huge workbook containing alot of values.

within this work book is several rows acting as titles.

What i need is to be able to input data into a userform then when i click ok it puts all the info into the correct columns.

my problem at the moment is on the userform button click event,
i want it to find the correct header (based on the selected combobox item) and insert a new row above it and then input data from the userform textbox`s into the correct columns.

But i think ive done something wrong with the if statements!?
can someone tell me how i can ammend this please?

heres my code:
Code:
Private Sub CommandButton1_Click()


Dim rngFound As Range

'input new data into engineering category

    If ComboBox1.Value = "Engineering" Then

        Set rngFound = Range("A:A").Find(What:="Manufacturing Bulks", _
        LookAt:=xlWhole, _
        LookIn:=xlFormulas, _
        MatchCase:=False)
        
        If rngFound Is Nothing Then
        MsgBox "Manufacturing Bulks Category was not found"
        Else
        rngFound.EntireRow.Insert
        End If

    End If

End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi lpking2005,

There is really nothing wrong with your code. I suspect that the problem is that the string "Manufacturing Bulks" does not exist in column A. This could be caused by something like an extra (invisible) space character at the start or end of the string. Using the xlWhole option in the LookIn parameter of the Find method forces the match to be <u>exact</u> in its entirety including spaces and other hidden characters. If this is the cause, an easy solution would be to use the xlPart option, or to trim the extra space characters.

Damon
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,283
Members
452,902
Latest member
Knuddeluff

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