Hello all,
I am hoping somebody can help me fix and speed up the VBA below.
My intent is to make Columns "T" to "Last Column with data" become rows. and the VBA i have below is just not working very good and its very slow
Current:
I am hoping somebody can help me fix and speed up the VBA below.
My intent is to make Columns "T" to "Last Column with data" become rows. and the VBA i have below is just not working very good and its very slow
Current:
Code:
Sub Columns_2_rows()
Dim rownum As Long
Dim rownum2 As Long
Dim colnum As Long
Dim wb As Workbook
Dim ws As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set ws = ThisWorkbook.Sheets.Add(After:= _
ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))
ws.Name = "Result"
Sheets("Raw_data").Select
Set wb = ActiveWorkbook
rownum = 2
rownum2 = 2
Sheets("Raw_data").Range("A1:S1").Copy Sheets("Result").Range("A1")
Sheets("Result").Range("T1").Value = "Date"
Sheets("Result").Range("U1").Value = "Value"
Do Until Sheets("Forecast Data").Cells(rownum, 1).Value = ""
colnum = 43
Do Until colnum = 67
Sheets("Raw_data").Range(Cells(rownum, 1), Cells(rownum, 19)).Copy Sheets("Result").Cells(rownum2, 1)
Sheets("Forecast Data").Cells(1, colnum).Copy Sheets("Result").Cells(rownum2, 20)
myval = Sheets("Raw_data").Cells(rownum, colnum).Value
If myval <> "0" Then
myval = myval / 1000
Else
myval = 0
End If
Sheets("Result").Cells(rownum2, 21) = myval
rownum2 = rownum2 + 1
colnum = colnum + 1
Loop
rownum = rownum + 1
Loop
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Last edited by a moderator: