PDA

View Full Version : How can I put multiple codes in 1 sheet?



genracela
04-18-2010, 10:48 PM
I have 3 different set of codes.

1st code: This is to copy data from another workbook to my working sheet


Sub CopyTo()
Application.ScreenUpdating = True
Workbooks("MS Clearing FIle 040610.xls").Sheets("pbu006all").Range("D2:D9000").Copy
Workbooks("MasterFile.xls").Sheets("Sheet2").Range("A4").PasteSpecial Paste:=xlPasteValues
Workbooks("MS Clearing FIle 040610.xls").Sheets("pbu006all").Range("E2:E9000").Copy
Workbooks("MasterFile.xls").Sheets("Sheet2").Range("B4").PasteSpecial Paste:=xlPasteValues

Workbooks("MS Clearing FIle 040610.xls").Sheets("pbu006all").Range("F2:F9000").Copy
Workbooks("MasterFile.xls").Sheets("Sheet2").Range("C4").PasteSpecial Paste:=xlPasteValues

Workbooks("MS Clearing FIle 040610.xls").Sheets("pbu006all").Range("G2:G9000").Copy
Workbooks("MasterFile.xls").Sheets("Sheet2").Range("D4").PasteSpecial Paste:=xlPasteValues

Workbooks("MS Clearing FIle 040610.xls").Sheets("pbu006all").Range("H2:H9000").Copy
Workbooks("MasterFile.xls").Sheets("Sheet2").Range("E4").PasteSpecial Paste:=xlPasteValues

Workbooks("MS Clearing FIle 040610.xls").Sheets("pbu006all").Range("I2:I9000").Copy
Workbooks("MasterFile.xls").Sheets("Sheet2").Range("F4").PasteSpecial Paste:=xlPasteValues

Workbooks("MS Clearing FIle 040610.xls").Sheets("pbu006all").Range("J2:J9000").Copy
Workbooks("MasterFile.xls").Sheets("Sheet2").Range("G4").PasteSpecial Paste:=xlPasteValues

Workbooks("MS Clearing FIle 040610.xls").Sheets("pbu006all").Range("K2:K9000").Copy
Workbooks("MasterFile.xls").Sheets("Sheet2").Range("H4").PasteSpecial Paste:=xlPasteValues

Workbooks("MS Clearing FIle 040610.xls").Sheets("pbu006all").Range("N2:N9000").Copy
Workbooks("MasterFile.xls").Sheets("Sheet2").Range("I4").PasteSpecial Paste:=xlPasteValues

Workbooks("MS Clearing FIle 040610.xls").Sheets("pbu006all").Range("O2:O9000").Copy
Workbooks("MasterFile.xls").Sheets("Sheet2").Range("J4").PasteSpecial Paste:=xlPasteValues

Workbooks("MS Clearing FIle 040610.xls").Sheets("pbu006all").Range("P2:P9000").Copy
Workbooks("MasterFile.xls").Sheets("Sheet2").Range("K4").PasteSpecial Paste:=xlPasteValues
Workbooks("MS Clearing FIle 040610.xls").Sheets("pbu006all").Range("Q2:Q9000").Copy
Workbooks("MasterFile.xls").Sheets("Sheet2").Range("L4").PasteSpecial Paste:=xlPasteValues

Workbooks("MS Clearing FIle 040610.xls").Sheets("pbu006all").Range("S2:S9000").Copy
Workbooks("MasterFile.xls").Sheets("Sheet2").Range("M4").PasteSpecial Paste:=xlPasteValues

Application.ScreenUpdating = True

End Sub


2nd Code: This is to delete all rows with blank cells


Sub DelNoneNumeric()
For X = Range("L" & Rows.Count).End(xlUp).Row To 9 Step -1
If Not IsNumeric(Range("L" & X).Text) Then Rows(X).Delete
Next
End Sub


3rd Code: To split cells



Sub SplittyMcSplitSplit()
Dim DataArray As Variant
Dim X As Long
Dim Y As Long
Dim Z As Long
Dim OldX As Long
Dim RowAdd As Long
For X = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
OldX = X
For Y = 10 To 14
If Y = 10 Then
RowAdd = 0
Else
RowAdd = UBound(DataArray) + 1
End If
If InStr(1, Cells(X + RowAdd, Y).Text, Chr(10)) > 0 Then
DataArray = Split(Cells(X + RowAdd, Y).Text, Chr(10))
For Z = 1 To UBound(DataArray) + 1
If Y = 10 Then
Rows(X).Copy
Rows(X).Insert Shift:=xlDown
Cells(X, Y).Formula = DataArray(Z - 1)
X = X + 1
Else
Cells(X + Z - 1, Y).Formula = DataArray(Z - 1)
End If
Next
X = OldX
End If
Next
Rows(X + Z - 1).Delete
Next
End Sub


Can I combine this as is? Without modifying?

mdmackillop
04-19-2010, 12:18 AM
Sub DoAll()
Call CopyTo
Call DelNoneNumeric
Call SplittyMcSplitSplit
End Sub

genracela
04-19-2010, 12:38 AM
I tried using it, but it keeps on giving me this error message:

Compile Error:
Sub or Function not defined:(

Aussiebear
04-19-2010, 02:18 AM
Do the individual subs create the same issue?

mdmackillop
04-19-2010, 02:32 AM
I tried using it, but it keeps on giving me this error message:

Compile Error:
Sub or Function not defined:(

What is highlighted?

genracela
04-19-2010, 04:34 PM
Sub DoAll()
Call CopyTo

:(

GTO
04-19-2010, 09:22 PM
Greetings Genracela,

Might you have the sub CopyTo or DelNonNumeric housed in a worksheet module, and the above in a standard module or other sheet's module?

Mark

mdmackillop
04-20-2010, 12:38 AM
or maybe more than one CopyTo?