Find and Replace in a Macro

P

pignataro1

Help! Trying to replace column with another and cannot resolve-please
advise
Thanks


Sub Macro6()
'
' Macro6 Macro
'

'
ActiveCell.Offset(-2, 0).Range("A1:Z2").Select
Selection.Copy
ActiveWindow.SmallScroll ToRight:=-5
ActiveCell.Offset(2, 0).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Range("A1:Z2")Find(!H)Replace [!G]
End Sub
 
W

WHA

Can you clarify what you need? I'm not familiar with your last line of
code, the one with the Find(!H)Replace [!G]. In any case, I'm not sure
which of two meanings of "replace" you're interested in:

1. Copy one range, then paste the contents on top of another range.
2. Do a find&replace within a range, replacing every instance of
<string> with <other string>

Those are the only two types I know of ...
 
P

pignataro1

Can you clarify what you need? I'm not familiar with your last line of
code, the one with the Find(!H)Replace [!G]. In any case, I'm not sure
which of two meanings of "replace" you're interested in:

1. Copy one range, then paste the contents on top of another range.
2. Do a find&replace within a range, replacing every instance of
<string> with <other string>

Those are the only two types I know of ...

Help! Trying to replace column with another and cannot resolve-please
advise
Thanks
Sub Macro6()
'
' Macro6 Macro
'
'
ActiveCell.Offset(-2, 0).Range("A1:Z2").Select
Selection.Copy
ActiveWindow.SmallScroll ToRight:=-5
ActiveCell.Offset(2, 0).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Range("A1:Z2")Find(!H)Replace [!G]
End Sub- Hide quoted text -

- Show quoted text -

That is the line I am having difficulty with. I am attempting to
copy and paste a range with a Macroand change only the column in the
process (H to G or any other column I need)
 
W

WHA

Ah, that's the problem. Addresses are permanent. The only way to
change a cell's address from "H1" to "G1" is to cut&paste the cell at
H1 to G1. Try something like

ActiveSheet.Range("H1:H8").Copy
ActiveSheet.Range("G1").PasteSpecial
Application.CutCopyMode = False

and see what that does. That's all I can think of here -- good luck
--- WHA

Can you clarify what you need? I'm not familiar with your last line of
code, the one with the Find(!H)Replace [!G]. In any case, I'm not sure
which of two meanings of "replace" you're interested in:
1. Copy one range, then paste the contents on top of another range.
2. Do a find&replace within a range, replacing every instance of
<string> with <other string>
Those are the only two types I know of ...
On Nov 30, 4:53 pm, (e-mail address removed) wrote:
Help! Trying to replace column with another and cannot resolve-please
advise
Thanks
Sub Macro6()
'
' Macro6 Macro
'
'
ActiveCell.Offset(-2, 0).Range("A1:Z2").Select
Selection.Copy
ActiveWindow.SmallScroll ToRight:=-5
ActiveCell.Offset(2, 0).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Range("A1:Z2")Find(!H)Replace [!G]
End Sub- Hide quoted text -
- Show quoted text -

That is the line I am having difficulty with. I am attempting to
copy and paste a range with a Macroand change only the column in the
process (H to G or any other column I need)
 
J

JLGWhiz

You cannot change the Header of the column from H to G. You can:

1. Hide G and H will move left to fill the gap.
2. Cut select column G, cut and paste to H1 which will replace everthing in
column H with column G data.

But the Find...Replace method will not work for what you described.

Can you clarify what you need? I'm not familiar with your last line of
code, the one with the Find(!H)Replace [!G]. In any case, I'm not sure
which of two meanings of "replace" you're interested in:

1. Copy one range, then paste the contents on top of another range.
2. Do a find&replace within a range, replacing every instance of
<string> with <other string>

Those are the only two types I know of ...

Help! Trying to replace column with another and cannot resolve-please
advise
Thanks
Sub Macro6()
'
' Macro6 Macro
'
'
ActiveCell.Offset(-2, 0).Range("A1:Z2").Select
Selection.Copy
ActiveWindow.SmallScroll ToRight:=-5
ActiveCell.Offset(2, 0).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Range("A1:Z2")Find(!H)Replace [!G]
End Sub- Hide quoted text -

- Show quoted text -

That is the line I am having difficulty with. I am attempting to
copy and paste a range with a Macroand change only the column in the
process (H to G or any other column I need)
 

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