Sub Twosheets()
Dim sws2, sws3, FileToOpen, sD As String
Dim x, y, vCol, vCl
Dim src, trg, src2, trg2, a, Ub, lro, lrr, i, j As Long
Dim ws, wso, wsr, wsa, wsb As Worksheet
Dim OpenWB As Workbook
Dim EndDate, StartDate As Date
Application.ScreenUpdating = False
Set ws = Sheets("studump")
On Error GoTo EH:
FileToOpen = Application.GetOpenFilename(Title:="Select File to Open where sheets will be added", _
FileFilter:="Excel Files (*.xls*),*xls*")
If FileToOpen = "False" Then Exit Sub
Set OpenWB = Workbooks.Open(Filename:=FileToOpen, ReadOnly:=False)
On Error GoTo -1
'On Error Resume Next
sws2 = InputBox("Please enter the name for the first worksheet?")
For Each wsa In OpenWB.Worksheets
If wsa.Name = sws2 Then
sws2 = sws2 & Int((900 - 1 + 1) * Rnd + 1)
Else
sws2 = sws2
End If
Next wsa
Sheets.Add(After:=Sheets(Sheets.Count)).Name = sws2
Set wso = OpenWB.Sheets(sws2)
sws3 = InputBox("Please enter the name for the 2nd worksheet?")
For Each wsb In OpenWB.Worksheets
If wsb.Name = sws3 Then
sws3 = sws3 & 1
Else
sws3 = sws3
End If
Next wsb
Sheets.Add(After:=Sheets(Sheets.Count)).Name = sws3
Set wsr = OpenWB.Sheets(sws3)
On Error GoTo -1
x = Split(InputBox("type from_what_row_number_in_sheet1, to_what_row_number_in_sheet1. Example : 2,200 "), ",")
src = x(0)
trg = x(1)
y = Split(InputBox("type from_what_row_number_in_sheet2, to_what_row_number_in_sheet2. Example : 200,500 "), ",")
src2 = y(0)
trg2 = y(1)
vCol = InputBox("Please enter the column letters you want transferred, seperated by commas, no spaces." & vbNewLine & "Enter atleast Column O")
vCl = Split(vCol, ",")
Ub = UBound(vCl)
sD = InputBox("Please enter which of the columns hold the dates." & vbNewLine & "Enter one letter")
With wso
ws.Range(vCl(0) & "1:" & vCl(Ub) & "1").Copy
wso.Range("A1").PasteSpecial xlPasteValuesAndNumberFormats
ws.Range(vCl(0) & src & ":" & vCl(Ub) & trg).Copy
wso.Range("A2").PasteSpecial xlPasteValuesAndNumberFormats
.Activate
lro = wso.Cells(Rows.Count, "A").End(xlUp).Row
For i = lro To 2 Step -1
If Application.WorksheetFunction.IsText(Cells(i, sD)) _
Or Cells(i, sD) = 0 Or IsNumeric(Cells(i, sD)) Then
Cells(i, sD).EntireRow.Delete
End If
Next i
wso.Range("B:B,D:H,J:N,P:Z,AC:XFD").EntireColumn.Delete
Columns(vCl(0) & ":" & vCl(Ub)).EntireColumn.AutoFit
wso.Range("A1:G1").Value = Array("student_name", "P-Percentage", "Cumulative Marks", "enroll_Date", "K-Percentage", "S-value", "L-valueDate")
With .Range("C1", .Cells(Rows.Count, "C").End(xlUp))
If WorksheetFunction.CountBlank(.Cells) + WorksheetFunction.CountIf(.Cells, 0) = 0 Then GoTo skipo
'Cells-What is this line for? I commented it out since itdoes not apparently do anything
.AutoFilter Field:=1, Criteria1:=0, Operator:=xlOr, Criteria2:=""
.Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
skipo:
.AutoFilterMode = False
End With
With wsr
.Activate
ws.Range(vCl(0) & "1:" & vCl(Ub) & "1").Copy
wsr.Range("A1").PasteSpecial xlPasteValuesAndNumberFormats
ws.Range(vCl(0) & src2 & ":" & vCl(Ub) & trg2).Copy
wsr.Range("A2").PasteSpecial xlPasteValuesAndNumberFormats
lrr = wsr.Cells(Rows.Count, "A").End(xlUp).Row
For j = lrr To 2 Step -1
If Application.WorksheetFunction.IsText(Cells(j, sD)) _
Or Cells(j, sD) = 0 Or IsNumeric(Cells(j, sD)) Then
Cells(j, sD).EntireRow.Delete
End If
Next j
wsr.Range("B:B,D:H,J:N,P:Z,AC:XFD").EntireColumn.Delete
Columns(vCl(0) & ":" & vCl(Ub)).EntireColumn.AutoFit
wsr.Range("A1:G1").Value = Array("student_name", "P-Percentage", "Cumulative Marks", "enroll_Date", "K-Percentage", "S-value", "L-valueDate")
With .Range("C1", .Cells(Rows.Count, "C").End(xlUp))
If WorksheetFunction.CountBlank(.Cells) + WorksheetFunction.CountIf(.Cells, 0) = 0 Then GoTo skipr
'Cells-What is this line for?
.AutoFilter Field:=1, Criteria1:=0, Operator:=xlOr, Criteria2:=""
.Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With
skipr:
End With
With Application
.CutCopyMode = False
.ScreenUpdating = True
End With
Exit Sub
EH:
MsgBox "This is an error " & Err.Description
With Application
.CutCopyMode = False
.ScreenUpdating = True
End With
On Error GoTo 0
End Sub
Bookmarks