Copy and Paste in Macro

A

AccessNewbie

I have created a macro to Find (Edit, Find) 34000 and when it finds 34000
excel is to copy 34000 and paste this two columns from where it is and bold
the original cell. My problem is when 34000 moves my macro won't work
because the macro is tied to the cell 34000 was in when I created the macro.
How can I rewrite the code to not get tied to 34000. Here is a sample of the
code:

Range("A1").Select
Cells.Find(What:="34000", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
Range("A12").Select
Selection.Font.Bold = True
 
G

GTVT06

hello, try this

Sub test()
Range("A1").Select
Cells.Find(What:="34000", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.Copy ActiveCell.Offset(0, 2)
ActiveCell.Font.Bold = True
End Sub
 
J

JLGWhiz

Sub test()
Dim c As Range
Set c = Cells.Find("34000", After:=Cells(65536, 1), _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If Not c Is Nothing Then
c.Offset(0, 2) = CStr(c.Value)
c.Offset(0, 2).Font.Bold = True
End If
End Sub
 
A

AccessNewbie

this is perfect. Thank You.

Can you tell me if I was searching for 34000 and wanted to delete the entire
row with that how would I change this?
 
G

GTVT06

this is perfect.  Thank You.  

Can you tell me if I was searching for 34000 and wanted to delete the entire
row with that how would I change this?






- Show quoted text -

Hello this will delete the row.

Range("A1").Select
Cells.Find(What:="34000", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.EntireRow.Delete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top