LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Copy Paired Info into Diff # of rows

Minor correction to the VBA code solution: When setting a cell to a new
value, use the Formula property instead of the Value property to insure
correct operation, for backward compatibility with older versions of Excel.
In older versions of Excel, setting the Value property did NOT change the
formula. The next time the workbook was recalculated, the value set by the
VBA code was overwritten. So the code inside the With statement should
technically be written as follows:

With ws
.Range(.Cells(rngStart.Row, 1), .Cells(rngEnd.Row, 1)).Formula = _
.Cells(rngStart.Row, 3).Value
.Range(.Cells(rngStart.Row, 2), .Cells(rngEnd.Row, 2)).Formula = _
.Cells(rngStart.Row, 4).Value
End With
--
Regards,
Bill


"Bill Renaud" wrote in message
...
As it turns out, there are 2 ways to solve this problem:
1. Use a spreadsheet formula.
2. Use a VBA macro.

================================================== =======
1. The spreadsheet formula method checks the row above each County Name to
see
if it is either blank or the value "County Non-Migrants". If it is, then
copy the value of column C:D on the row to column A:B of the same row,
otherwise copy the value from the row above. Follow these steps:

1. Enter the following formula into cells $A$5:$B$17 (where each County

Name
is listed in column $E):
=IF(OR(ISBLANK($E4),$E4="County Non-Migrants"),C5,A4)
2. Then Copy and Paste|Special Values to put the value back into these

cells
and remove the formulas.

================================================== =======
2. The VBA macro method:

Public Sub CopyCDtoAB()
Dim ws As Worksheet
Dim rngStart As Range 'Starting County Name.
Dim rngEnd As Range 'End of data section at "County Non-Migrants".

Set ws = ActiveSheet
Set rngStart = ws.Cells(1, 5).End(xlDown)

Do
Set rngEnd = ws.Cells.Find(What:="County Non-Migrants", _
After:=rngStart, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If (rngEnd Is Nothing) Then Exit Do
If (rngEnd.Row < rngStart.Row) Then Exit Do

'End of this section of data has been found.
'Copy values to columns $A and $B.
With ws
.Range(.Cells(rngStart.Row, 1), .Cells(rngEnd.Row, 1)).Value = _
.Cells(rngStart.Row, 3).Value
.Range(.Cells(rngStart.Row, 2), .Cells(rngEnd.Row, 2)).Value = _
.Cells(rngStart.Row, 4).Value
End With
Set rngStart = rngEnd.Offset(1, 0)
Loop
End Sub

--
Regards,
Bill






 
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
Need Macro- Insert rows based on dates and copy info from that row Katerinia Excel Discussion (Misc queries) 1 April 6th 10 08:02 PM
Copy Value of Active cell and 25 rows above to a diff worksheet ash3154 Excel Discussion (Misc queries) 4 September 2nd 09 12:56 AM
Copy info into empty cells below info, until finds cell with new d Fat Jack Utah Excel Discussion (Misc queries) 3 November 16th 08 08:34 PM
VBA to Pull info from 2 diff tabs from the same spreadsheet mike Excel Discussion (Misc queries) 0 December 7th 05 06:41 PM
Copy Paired Info to Different number of Rows No Name Excel Programming 3 April 14th 04 06:34 PM


All times are GMT +1. The time now is 02:21 PM.

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

About Us

"It's about Microsoft Excel"