Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can som1 correct this code please (pretty simple i think)

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
hello
when this wrx, excel should copy a name and paste it into th first empty cell on a dffrnt sheet, however it just pastes the word 'TRUE':

here's the code:

Sub cmdProcess_click()
Application.ScreenUpdating = False

Worksheets("Invoice").Select
Range("B3").Select

With Worksheets("Previous Purchases").Range("C65535").End(xlUp)
If .Address = "$C$3" And IsEmpty(.Value) Then
.Value = Worksheets("invoice").Select
Else: .Offset(1, 0).Value = Worksheets("invoice").Select
End If
End With

End Sub


...i think i need to change what .value equals, but what to?
hlp me pls
cheers
 
The problem is with this statement:

Code:
Else: .Offset(1, 0).Value = Worksheets("invoice").Select

Should be:

Code:
    Else: .Offset(1, 0).Value = Worksheets("invoice").Selection

or

Code:
    Else: .Offset(1, 0).Value = Worksheets("invoice").ActiveCell

Your code was setting the value of a cell to the condition of whether the worksheet was selected, which is true because that's what WorkSheets("SheetName").Select does!

HTH
M. Smith
 
hello again killer
Have you given up on the 5th column of a listbox thing? If not, this guy, Mike, might be able to help - tee hee.

happy friday
roll on tomorrow
;-) If a man says something and there are no women there to hear him, is he still wrong?
 
i decided to change it a little bit, so now i have a text box and a button to add items, so its mostly working, but my lookup table has stopped working.

=IF(ISERROR(VLOOKUP(D3,Prices,3)),"NOTHING SELECTED",(VLOOKUP(D3,Prices,3)))

thats wot a cell is
but if i type a correct code in D3, it gives me the wrong value. not only this but, as long as i type a correct code, it will give me the saem value..help?
 
mike, .activecell or .selection still doesn't work "object doesn't support this property or method"
 
My error. It always seems to me that the Selection and ActiveCell properties should belong to the Worksheet object, but they don't; it's the Window object. Here is your modified procedure:

Code:
Sub cmdProcess_click()
    
Application.ScreenUpdating = False
Worksheets("Invoice").Select
Range("B3").Select
With Worksheets("Previous Purchases").Range("C65535").End(xlUp)
    If .Address = "$C$3" And IsEmpty(.Value) Then
      .Value = ActiveWindow.ActiveCell
    Else
      .Offset(1, 0).Value = ActiveWindow.ActiveCell
    End If
End With

End Sub

BTW, I don't see how the line
Code:
.Value = ActiveWindow.ActiveCell
will ever run since if the construct
Code:
.Range("C65535").End(xlUp)
returns address $C$3, that cell by definition will contain a value. Therefore the condition
Code:
If .Address = "$C$3" And IsEmpty(.Value) Then
will never be satisfied.

Regards,
Mike
 
mike
i actually did the code for the xlup bit
it was originally A1 and was to allow for the first time the code was run on an empty sheet to prevent overwriting the same cell

it would need to be modified slightly for a header row etc...

Loom
nearly there
happy friday
;-) If a man says something and there are no women there to hear him, is he still wrong?
 
Loomah,

Thanks for the explanation. [thumbsup2] The code makes more sense now. Not to rub it in, but Thursday was my "Happy Friday"; I took the day off! [wink]


killer,

Change your VLookup formula to look like the following (add the FALSE parameter -- This tells VLookup to find an exact match and the list does not need to be in ascending order):

=IF(ISERROR(VLOOKUP(D3,Prices,3,FALSE)),"NOTHING SELECTED",(VLOOKUP(D3,Prices,3,FALSE)))
 
i really didnt know that parameter existed. so thanks, now everything ive done so far works

now i can rest
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top