Very Easy Excel VBA Question

VBeginner
03-18-2003, 09:16 PM
Hi again,

I have code to search in a column for a particular value, then insert a row where it is found. This leaves with the inserted row activated. I then want to put TextBox1.Text into Column E of this inserted Row, and ComboBox1.Value into Column F.

For some reason I can't. The corresponding code is as follows:

If iReturn = vbNo Then
Exit Sub
Else
Set Found = Sheets("Codes").Columns("F:F").Find(What:=ComboBox1.Value, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)
'Check whether something is found

If Not Found Is Nothing Then

Found.Rows.EntireRow.Insert Shift:=xlDown

Row.Column(5) = TextBox1.Text 'This is the Problem
Row.Column(6) = ComboBox1.Value

Else

End If


Thanks,
Nick

icjackson
03-19-2003, 01:19 AM
Try using Cells to reference the sheet. The following will insert the form values in the row above the found row.
Cells(Found.Row-1,5) = TextBox1.Text
Cells(Found.Row-1,6) = ComboBox1.Value

VBeginner
03-19-2003, 08:47 AM
cool....thanks icjackson it worked.

I do have a slightly different problem now along the same lines.

here's the code:

Sheets("Initial").Activate
Columns("D:D").Activate

Set Foundi = Sheets("Initial").Columns("D:D").Find(What:=ComboBox1.Value, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False)
'Check whether something is found

If Not Foundi Is Nothing Then

Foundi.Rows.EntireRow.Insert Shift:=xlDown

Cells(Foundi.Row - 1, 5) = TextBox1.Text
Cells(Foundi.Row - 1, 4) = ComboBox1.Value
Cells(Foundi.Row, 6).Copy
Cells(Foundi.Row - 1, 6).Paste
Cells(Foundi.Row, 7).Copy
Cells(Foundi.Row - 1, 7).Paste
Cells(Foundi.Row, 8).Copy
Cells(Foundi.Row - 1, 8).Paste


Else

End If

I am getting an error on the paste commands. If it matters it's the formula that needs to be copied and pasted not the values.

If anyone knows what I need to call it, it would be much appreciated.

Thanks,
Nick

Wamphyri
03-19-2003, 10:14 AM
The reason for the error is that there is no paste method for range objects (which cells is). You must use PasteSpecial instead.
for example

Cells(1, 1).PasteSpecial xlPasteFormulas

icjackson
03-20-2003, 12:17 AM
And I guess you could always do something like:
Cells(Foundi.Row - 1, 6).Formula = Cells(Foundi.Row, 6).Formula

VBeginner
03-21-2003, 09:48 PM
Thanks guys...works great.....

small adapatation now.

One other thing what syntax would i be required to copy the found row, then insert a row and paste just the formulas for the entire row

I tried

Foundi.Rows.EntireRow.Copy
Foundi.Rows.EntireRow.Insert Shift:=xlDown

Which will paste the entire cells however, and i need just the formulas.

Thanks again in advance
Nick

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum