View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Zak Zak is offline
external usenet poster
 
Posts: 144
Default Code not working correctly

Hi,

I have two problems with the same code - I am finding that when i run the
macro, it copies the specified cells into the report sheet but it doesnt copy
from the 1st cell/row under the column header row.. (for examples, intead of
copying from C2 it copies from C3 onwards.. but there is a filter on so C2 is
not actually C2 but something else - C**- dont know if this matters).

The code from where it selects the cells from: (before this bit of the code
there are some conditions - if cell =blank or 0 then hide, dont know if this
will affect anything.)

'selects columns
For Each cell In Range("Y2:Y65536")
If cell.Rows.Hidden = False Then
If cell.Value "" Then
Range("C" & cell.Rows.Row & ":" & "D" & cell.Rows.Row & "," _
& "G" & cell.Rows.Row & ":" & "H" & cell.Rows.Row & "," _
& "S" & cell.Rows.Row & ":" & "Y" & cell.Rows.Row & "," _
& "AJ" & cell.Rows.Row & ":" & "AJ" & cell.Rows.Row).Select
'paste them to other sheet
Selection.Copy
Worksheets("Report").Activate
If Range("A1") = "" Then
Worksheets("GTS_C_SI").Activate
Range("C1:D1,G1:H1,S1:Y1,AJ1").Select
Selection.Copy
Worksheets("Report").Activate
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteAll
Application.CutCopyMode = False
Else
Range("A65536").End(xlUp).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteAll
Application.CutCopyMode = False
End If
Worksheets("GTS_C_SI").Activate
End If
End If
Next cell
Worksheets("Report").Activate
Cells.Select
Cells.EntireColumn.AutoFit
Cells.EntireRow.AutoFit
Range("A1").Select
Worksheets("GTS_C_SI").Activate
With Application
.DisplayAlerts = True
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub


The second problem I am having is with the below line:

Range("C1:D1,G1:H1,S1:Y1,AJ1").Select

Everything in the above is fine just that i dont want it to select S1:Y1 -
which selects everything between S&Y. I want it to just select S and Y. I
have tried changing the code to just S1 and Y1 and numerous other things but
i get strange results! like the info is there but the column header is
missing and info all mixed up.

Please help. Thanks!