Rowland Hamilton
Active Member
- Joined
- Nov 13, 2009
- Messages
- 250
Folks,
So far my rewrite takes hiker95's code and copies all same except the data column. I'm getting 2 data type columns (ie the column created with the former column header values). How do I fix this?
Thank you, Rowland Hamilton
So far my rewrite takes hiker95's code and copies all same except the data column. I'm getting 2 data type columns (ie the column created with the former column header values). How do I fix this?
Thank you, Rowland Hamilton
Code:
Sub ReorgDataV3()
'Option Explicit works above this one (if all other module macros worked,too)
' Modfied from hiker95, 04/19/2011
'
Dim ws1 As Worksheet 'Source worksheet
Dim wsR As Worksheet 'Results worksheet
Dim LR As Long 'Last row
Dim a As Long 'iterated cell in loop
Dim NR As Long 'Next Row
Dim LC As Long 'LC is last column
Application.ScreenUpdating = False
Set ws1 = Worksheets("HC-Stacked")
If Not Evaluate("ISREF(Results!A1)") Then Worksheets.Add(After:=ws1).Name = "Results"
Set wsR = Worksheets("Results")
wsR.UsedRange.Clear
wsR.Range("A1:D1") = [{"Location","Home Department","Week","HC"}]
'Replace this: LR = ws1.Cells(Rows.Count, 1).End(xlUp).Row
LR = ws1.Range(Rows.Count, 2).End(xlUp).Row
'Added Last column derivation
LC = ws1.Range(1, Columns.Count).End(xlToLeft).Column
For a = 2 To LR Step 1
NR = wsR.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
'replace: wsR.Range("A" & NR).Resize(12, 2).Value = ws1.Range("A" & a).Resize(, 2).Value
wsR.Range("A" & NR).Resize(LC - 2, 2).Value = ws1.Range("A" & a).Resize(, 2).Value
'replace: wsR.Range("C" & NR).Resize(12).Value = Application.Transpose(ws1.Range("C1:N1").Value)
wsR.Range("C" & NR).Resize(LC - 2).Value = Application.Transpose(ws1.Range(Cells(1, 3), Cells(1, LC)).Value)
'replace: wsR.Range("D" & NR).Resize(12).Value = Application.Transpose(ws1.Range("C" & a & ":N" & a).Value)
wsR.Range("D" & NR).Resize(LC - 2).Value = Application.Transpose(ws1.Range(Cells(a, 3), Cells(1, LC)).Value)
Next a
wsR.UsedRange.Columns.AutoFit
wsR.Activate
Application.ScreenUpdating = True
End Sub
Code:
Sub ReorgDataV1()
'Option Explicit works above this one (if all other module macros worked,too)
' hiker95, 04/19/2011
Dim ws1 As Worksheet, wsR As Worksheet
Dim LR As Long, a As Long, NR As Long
Application.ScreenUpdating = False
Set ws1 = Worksheets("HC-Stacked")
If Not Evaluate("ISREF(Results!A1)") Then Worksheets.Add(After:=ws1).Name = "Results"
Set wsR = Worksheets("Results")
wsR.UsedRange.Clear
wsR.Range("A1:D1") = [{"Location","Home Department","Week","HC"}]
LR = ws1.Cells(Rows.Count, 1).End(xlUp).Row
For a = 2 To LR Step 1
NR = wsR.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
wsR.Range("A" & NR).Resize(12, 2).Value = ws1.Range("A" & a).Resize(, 2).Value
wsR.Range("C" & NR).Resize(12).Value = Application.Transpose(ws1.Range("C1:N1").Value)
wsR.Range("D" & NR).Resize(12).Value = Application.Transpose(ws1.Range("C" & a & ":N" & a).Value)
Next a
wsR.UsedRange.Columns.AutoFit
wsR.Activate
Application.ScreenUpdating = True
End Sub