robertlozar
New Member
- Joined
- Apr 7, 2011
- Messages
- 3
Hello, I am very new to VBA. I need to generate a report from excel output into an Excel report page. I found the example Macro "MoveActiveRowAtoC" which has been the model for my work so far. It does well for anything in the first column. I have been frustrated in that I want to check to see if there is something in the second column which also needs to be printed on the second sheet in the second column - and thus also search the third and fourth columns for similar text that should be printed to the next available row on sheet2. Below is my current version, but I know there must be a better way. Can someone help please?
Thank you, Bob
Using Excel 2010
Sub MoveActiveRowAtoC()
'If there is an entry in the current cell of the first sheet, place 3 columns in sheet2
Dim lst As Long 'line in sheet2
Dim CurrRw As Long 'current row in sheet1
Dim Time As Long
Dim NextFreeRow As Long
Time = 1
CurrRw = 1
Do While Time <= 11
NextFreeRow = 1
lst = Sheet2.Range("A" & Rows.Count).End(xlUp).Row + 1
If ActiveSheet.Name <> "Sheet1" Then Exit Sub
If lst >= 20 Then 'alter to be the last row of table
MsgBox "Table Limit Reached!!, data will not be copied"
Exit Sub
End If
With Sheet2.Range("A1:A3").Font 'Format Title Rows 1 to 3
.Bold = True
.Size = 15
.ColorIndex = 5
End With
NextFreeRow = lst + 1
Cells(CurrRw, 1).Resize(1, 3).Copy Sheet2.Cells(lst, 1) 'copy columns A-c of ActiveRow to next available in Sheet2
Sheet2.Cells(lst, 1).Font.Size = 14
Cells(CurrRw + 1, 2).Resize(1, 3).Copy Sheet2.Cells(NextFreeRow, 1)
Time = Time + 1
CurrRw = CurrRw + 1
Loop
End Sub
Thank you, Bob
Using Excel 2010
Sub MoveActiveRowAtoC()
'If there is an entry in the current cell of the first sheet, place 3 columns in sheet2
Dim lst As Long 'line in sheet2
Dim CurrRw As Long 'current row in sheet1
Dim Time As Long
Dim NextFreeRow As Long
Time = 1
CurrRw = 1
Do While Time <= 11
NextFreeRow = 1
lst = Sheet2.Range("A" & Rows.Count).End(xlUp).Row + 1
If ActiveSheet.Name <> "Sheet1" Then Exit Sub
If lst >= 20 Then 'alter to be the last row of table
MsgBox "Table Limit Reached!!, data will not be copied"
Exit Sub
End If
With Sheet2.Range("A1:A3").Font 'Format Title Rows 1 to 3
.Bold = True
.Size = 15
.ColorIndex = 5
End With
NextFreeRow = lst + 1
Cells(CurrRw, 1).Resize(1, 3).Copy Sheet2.Cells(lst, 1) 'copy columns A-c of ActiveRow to next available in Sheet2
Sheet2.Cells(lst, 1).Font.Size = 14
Cells(CurrRw + 1, 2).Resize(1, 3).Copy Sheet2.Cells(NextFreeRow, 1)
Time = Time + 1
CurrRw = CurrRw + 1
Loop
End Sub