Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Search and Replace, or Add New Row

I am using Excel 2003. I mistakenly posted this originally under General
Questions.

Worksheet1 contains columns
(A) Invoice
(B) Name
(C) Address
(D) P.O.# ... and others.

I need to perform a search of column A using an invoice number and if it IS
FOUND, then replace the entire row with new data.

If the invoice number IS NOT FOUND, then I need to add a new row.

Is there a simple way to do this?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Search and Replace, or Add New Row

Try

Sub Macro()

Dim lngNewRow As Long
Dim varFound As Variant
Dim varSearch As Variant

varSearch = InputBox("Enter Invoice Number")
Set varFound = Columns(1).Find(varSearch)

If Not varFound Is Nothing Then
Range("A" & varFound.Row).Offset(0, 1).Resize(, 3).ClearContents
MsgBox "Cleared"
Else
lngNewRow = Cells(Rows.Count, "A").End(xlUp).Row + 1
MsgBox "Added"
End If


End Sub


--
Jacob (MVP - Excel)


"GEdwards" wrote:

I am using Excel 2003. I mistakenly posted this originally under General
Questions.

Worksheet1 contains columns
(A) Invoice
(B) Name
(C) Address
(D) P.O.# ... and others.

I need to perform a search of column A using an invoice number and if it IS
FOUND, then replace the entire row with new data.

If the invoice number IS NOT FOUND, then I need to add a new row.

Is there a simple way to do this?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Search and Replace, or Add New Row

If you need to clear the entire row then replace the below line

Range("A" & varFound.Row).Offset(0, 1).Resize(, 3).ClearContents

'with

Rows(lngNewRow).ClearContents


--
Jacob (MVP - Excel)


"Jacob Skaria" wrote:

Try

Sub Macro()

Dim lngNewRow As Long
Dim varFound As Variant
Dim varSearch As Variant

varSearch = InputBox("Enter Invoice Number")
Set varFound = Columns(1).Find(varSearch)

If Not varFound Is Nothing Then
Range("A" & varFound.Row).Offset(0, 1).Resize(, 3).ClearContents
MsgBox "Cleared"
Else
lngNewRow = Cells(Rows.Count, "A").End(xlUp).Row + 1
MsgBox "Added"
End If


End Sub


--
Jacob (MVP - Excel)


"GEdwards" wrote:

I am using Excel 2003. I mistakenly posted this originally under General
Questions.

Worksheet1 contains columns
(A) Invoice
(B) Name
(C) Address
(D) P.O.# ... and others.

I need to perform a search of column A using an invoice number and if it IS
FOUND, then replace the entire row with new data.

If the invoice number IS NOT FOUND, then I need to add a new row.

Is there a simple way to do this?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Search and Replace, or Add New Row

Neither of the ClearContents lines work.
--
Thank you

Aussie Bob C
Little cost to carry knowledge with you.
Win XP P3 Office 2007 on Mini Mac using VMware.


"Jacob Skaria" wrote:

If you need to clear the entire row then replace the below line

Range("A" & varFound.Row).Offset(0, 1).Resize(, 3).ClearContents

'with

Rows(lngNewRow).ClearContents


--
Jacob (MVP - Excel)


"Jacob Skaria" wrote:

Try

Sub Macro()

Dim lngNewRow As Long
Dim varFound As Variant
Dim varSearch As Variant

varSearch = InputBox("Enter Invoice Number")
Set varFound = Columns(1).Find(varSearch)

If Not varFound Is Nothing Then
Range("A" & varFound.Row).Offset(0, 1).Resize(, 3).ClearContents
MsgBox "Cleared"
Else
lngNewRow = Cells(Rows.Count, "A").End(xlUp).Row + 1
MsgBox "Added"
End If


End Sub


--
Jacob (MVP - Excel)


"GEdwards" wrote:

I am using Excel 2003. I mistakenly posted this originally under General
Questions.

Worksheet1 contains columns
(A) Invoice
(B) Name
(C) Address
(D) P.O.# ... and others.

I need to perform a search of column A using an invoice number and if it IS
FOUND, then replace the entire row with new data.

If the invoice number IS NOT FOUND, then I need to add a new row.

Is there a simple way to do this?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Search and Replace, or Add New Row GEdwards Excel Discussion (Misc queries) 1 April 21st 10 08:20 AM
Search Replace in VBA pamalpass Excel Programming 5 February 27th 06 01:46 AM
Search & Replace John Keturi Excel Programming 4 May 31st 04 01:37 AM
Search & Replace John Keturi Excel Programming 2 May 28th 04 05:11 AM
Search and Replace... Patrick Lamb Excel Programming 0 October 1st 03 05:07 PM


All times are GMT +1. The time now is 11:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"