PC Review


Reply
Thread Tools Rate Thread

On Cell click, start macro

 
 
camcrazy08
Guest
Posts: n/a
 
      17th Jan 2008
Here is what I am looking to do. I need to make this macro where, when I
click on a cell in column B on sheet one, it would copy the contents of that
cell, and insert the value into sheet two in Range("B4"), then call the macro
Searchforstring. How can I do this? Here is what I have so far...

Sub SearchandFind()

On Cell Click

ActiveCell.Copy
Sheets("Sheet2").Activate
Range("B4").PasteSpecial xlPasteValues

Call SearchForString

End Sub

Obviously the "On Cell Click" is incorrect. Does anyone have any possible
idea as to how I can complete this? Thank you for any help that you can be!

In case anyone is wondering or want to see the SearchForString vba (for
incorporation into this macro, or to tell me how inefficient this macro is,
or suggestions on another way to accomplish this):

Sub SearchForString()

Profit = Range("B4")

Sheets("Sheet2").Select
Range("A2:K100").ClearContents

Sheets("$1k Detail").Select

Dim LSearchRow As Integer
Dim LCopyToRow As Integer

On Error GoTo Err_Execute

'Start search in row 2
LSearchRow = 2

'Start copying data to row 2 in Sheet2 (row counter variable)
LCopyToRow = 2

While Len(Range("B" & CStr(LSearchRow)).Value) > 0

'If value in column B = Range "Profit", copy entire row to Sheet1
If Range("B" & CStr(LSearchRow)).Value = Profit Then

'Select row in Sheet1 to copy
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
Selection.Copy

'Paste row into Sheet2 in next row
Sheets("Sheet2").Select
Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
ActiveSheet.Paste

'Move counter to next row
LCopyToRow = LCopyToRow + 1

'Go back to Sheet1 to continue searching
Sheets("$1k Detail").Select

End If

LSearchRow = LSearchRow + 1

Wend

'Position on cell A3
Application.CutCopyMode = False
Sheets("Sheet2").Select
Range("A2").Select

Exit Sub

Err_Execute:
MsgBox "An error occurred."

End Sub


THANK YOU!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
On Cell click, start macro camcrazy08 Microsoft Excel Programming 4 18th Jan 2008 02:36 PM
Start a macro when click on tab sheet Nancy Microsoft Excel Programming 4 29th Sep 2007 04:56 AM
Click in cell to run macro =?Utf-8?B?YWxpc3Rldw==?= Microsoft Excel Misc 7 20th Feb 2007 05:03 PM
Re: Run Macro on Cell Click.. scottymelloty Microsoft Excel Programming 1 17th Nov 2004 06:15 PM
Can't start macro via button click dan Microsoft Excel Programming 1 3rd Nov 2004 08:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:06 PM.