Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Data replacement

Hi All,

I have data for 100 lines in column A and column B -
Eg - Column A consists -
A
B
C
D
-
-
-
Till 100 or more lines

In Column B -

Sales
International
News
-
-
-
-
Till 100 or more lines

My query starts here -

When creating a macro to format a report I need to Call column B data
in place of column A data.

ie, where ever the column A data exists it should be replaced with
column B data.

Note - The occourence of column A data is dynamic.

Could someone help me out.

Thanks
Thyag.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Data replacement

This assumes that the table is in Sheet1 and the report is in Sheet2:

Sub xlator()
n = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To n
v1 = Sheets("Sheet1").Cells(i, 1).Value
v2 = Sheets("Sheet1").Cells(i, 2).Value
For Each r In Sheets("Sheet2").UsedRange
r.Value = Replace(r.Value, v1, v2)
Next
Next
End Sub

--
Gary''s Student - gsnu2007


"Thyag" wrote:

Hi All,

I have data for 100 lines in column A and column B -
Eg - Column A consists -
A
B
C
D
-
-
-
Till 100 or more lines

In Column B -

Sales
International
News
-
-
-
-
Till 100 or more lines

My query starts here -

When creating a macro to format a report I need to Call column B data
in place of column A data.

ie, where ever the column A data exists it should be replaced with
column B data.

Note - The occourence of column A data is dynamic.

Could someone help me out.

Thanks
Thyag.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 411
Default Data replacement

Hi Gary's Student

How do you dim the variables?

I used:

Dim n As Range
Dim i As Integer
Dim v1 As Range
Dim v2 As Range
Dim r As Range

This produced a runtime error 91; object variable or with block
variable not set at n = Sheets("Sheet1").Cells(Rows.Count,
"A").End(xlUp).Row

So a tried,

set n = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row

This produced a runtime error 424, object required at set n =
Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row

What am I doing wrong?

Dan



So
On Oct 22, 8:59 am, Gary''s Student
wrote:
This assumes that the table is in Sheet1 and the report is in Sheet2:

Sub xlator()
n = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To n
v1 = Sheets("Sheet1").Cells(i, 1).Value
v2 = Sheets("Sheet1").Cells(i, 2).Value
For Each r In Sheets("Sheet2").UsedRange
r.Value = Replace(r.Value, v1, v2)
Next
Next
End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Data replacement

I'd try:

Dim n As Long 'it holds a (row) number
Dim i As Long 'it also holds a number
Dim v1 As Variant 'or string??
Dim v2 As Variant 'or String
Dim r As Range 'it's a range (a single cell) in the used range.

dan dungan wrote:

Hi Gary's Student

How do you dim the variables?

I used:

Dim n As Range
Dim i As Integer
Dim v1 As Range
Dim v2 As Range
Dim r As Range

This produced a runtime error 91; object variable or with block
variable not set at n = Sheets("Sheet1").Cells(Rows.Count,
"A").End(xlUp).Row

So a tried,

set n = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row

This produced a runtime error 424, object required at set n =
Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row

What am I doing wrong?

Dan

So
On Oct 22, 8:59 am, Gary''s Student
wrote:
This assumes that the table is in Sheet1 and the report is in Sheet2:

Sub xlator()
n = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To n
v1 = Sheets("Sheet1").Cells(i, 1).Value
v2 = Sheets("Sheet1").Cells(i, 2).Value
For Each r In Sheets("Sheet2").UsedRange
r.Value = Replace(r.Value, v1, v2)
Next
Next
End Sub


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 411
Default Data replacement

Thanks Dave!

On Oct 22, 1:42 pm, Dave Peterson wrote:
I'd try:

Dim n As Long 'it holds a (row) number
Dim i As Long 'it also holds a number
Dim v1 As Variant 'or string??
Dim v2 As Variant 'or String
Dim r As Range 'it's a range (a single cell) in the used range.



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
Data replacement between worksheets JLB Excel Discussion (Misc queries) 2 June 26th 07 09:20 AM
Replacement T De Villiers[_45_] Excel Programming 0 July 21st 06 03:53 PM
Replacement T De Villiers[_47_] Excel Programming 0 July 21st 06 03:53 PM
Replacement T De Villiers[_44_] Excel Programming 0 July 21st 06 03:52 PM
Replacement or deletion of data after filter Seeking help[_8_] Excel Programming 0 July 6th 06 03:36 AM


All times are GMT +1. The time now is 09:31 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"