Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 49
Default Please Help

Greg,

Your macro copies all data till 103 from sheet 1 but when it reaches 103 it
sees 103 is missing and delets the column and put 0 in all the columns after
that like 104 had a 0 value and all the cells after that even though they had
data in sheet1.

"Greg Wilson" wrote:

Appended is my interpretation of your code in a condenced form. However, it
doesn't do anything more than what you already have. I don't understand what
you are trying to do. If you let us know how this fails to do what you want
then it will illustrate your situation.

Sub copycells()
Dim header As Range, r As Range
Dim c As Range, c1 As Range, c2 As Range

With Sheets("Sheet1")
'use c to define header range
Set c = .Cells(1, Columns.Count).End(xlToLeft)
Set header = .Range(.Range("C1"), c)
For Each c1 In header.Cells
Set c2 = Sheets("Sheet2").Range(c1.Address)
If c1.Value = c2.Value Then
'use c to define column containing data
Set c = .Cells(Rows.Count, c1.Column).End(xlUp)
Set r = .Range(c1(2), c)
r.Copy c2(2)
Else
c2.Value = c1.Value
c2(2).Resize(24, 1).Value = 0
End If
Next
End With
End Sub

Regards,
Greg

 
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



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