M
Matt
I am currently writing a macro that will read data out of columns and
write that data out to rows on a separate sheet. I need to write the
data out to rows in a separate sheet (going to save that as a CSV).
When I do the first for each loop it works fine. However when it goes
to do the second one - it is reading out of the S column - rather than
the specified J range. I figured out that S is the exact distance
from J that J is from A - so it is almost as if the sheet has become
offset. I am not sure why. I don't usually develop in the Excel
model - so I suspect there are some protocols that I am unaware of.
Here is the code (its a bit rough - I am still working on the logic
and haven't taken the time to polish it)
Sub MoveInfo()
Dim wSheet As Worksheet
Dim rCell As Range
Dim vCell As Range
Dim rowCount As Integer
rowCount = 0
For Each wSheet In ActiveWorkbook.Sheets
If wSheet.Name <> "Sheet3" Then
Sheets(wSheet.Name).Select
rowCount = rowCount + 1
For Each rCell In Range("A1:A33")
If rCell.Cells.Value <> "" Then
With rCell.Range("A1:A1")
.Copy
Sheets("Sheet3").Select
Cells(rowCount, Columns.Count).End(xlToLeft)(1,
2).PasteSpecial xlValues
Sheets(wSheet.Name).Select
End With
End If
Next rCell
End If
rowCount = rowCount + 1
Sheets(wSheet.Name).Select
For Each vCell In Range("J1:J33")
If vCell.Cells.Value <> "" Then
With vCell.Range("J1:J1")
.Copy
Sheets("Sheet3").Select
Cells(rowCount, Columns.Count).End(xlToLeft)(1,
2).PasteSpecial xlValues
Sheets(wSheet.Name).Select
End With
End If
Next vCell
Next wSheet
End Sub
Thanks in advance for any help or pushes in the right direction.
Thanks,
Matt
write that data out to rows on a separate sheet. I need to write the
data out to rows in a separate sheet (going to save that as a CSV).
When I do the first for each loop it works fine. However when it goes
to do the second one - it is reading out of the S column - rather than
the specified J range. I figured out that S is the exact distance
from J that J is from A - so it is almost as if the sheet has become
offset. I am not sure why. I don't usually develop in the Excel
model - so I suspect there are some protocols that I am unaware of.
Here is the code (its a bit rough - I am still working on the logic
and haven't taken the time to polish it)
Sub MoveInfo()
Dim wSheet As Worksheet
Dim rCell As Range
Dim vCell As Range
Dim rowCount As Integer
rowCount = 0
For Each wSheet In ActiveWorkbook.Sheets
If wSheet.Name <> "Sheet3" Then
Sheets(wSheet.Name).Select
rowCount = rowCount + 1
For Each rCell In Range("A1:A33")
If rCell.Cells.Value <> "" Then
With rCell.Range("A1:A1")
.Copy
Sheets("Sheet3").Select
Cells(rowCount, Columns.Count).End(xlToLeft)(1,
2).PasteSpecial xlValues
Sheets(wSheet.Name).Select
End With
End If
Next rCell
End If
rowCount = rowCount + 1
Sheets(wSheet.Name).Select
For Each vCell In Range("J1:J33")
If vCell.Cells.Value <> "" Then
With vCell.Range("J1:J1")
.Copy
Sheets("Sheet3").Select
Cells(rowCount, Columns.Count).End(xlToLeft)(1,
2).PasteSpecial xlValues
Sheets(wSheet.Name).Select
End With
End If
Next vCell
Next wSheet
End Sub
Thanks in advance for any help or pushes in the right direction.
Thanks,
Matt