Compilation Error When Trying to merge two(2) macros !!

WantToMasterExcel

New Member
Joined
Feb 10, 2012
Messages
20
I am trying to merge below 6 macros (from 2-7) into one macro above them named Sub Macros(1). I am getting compilation error. I am not a programmer, therefore I just play with plug n error method. I can copy Macro#1, but it is way too LONG. Thanks in advance to experts here at Mr.Excel.

Sub Macro2()
Dim wsh As Worksheet, Column As Long, lngEndRowInv As Long
Set wsh = ActiveSheet
i = 2
lngEndRowInv = wsh.Range("A" & wsh.Rows.Count).End(xlUp).Row
While i <= lngEndRowInv
If Cells(i, "S") Like "*CRA*" And Cells(i, "T") Like "*CRS*" Then
Cells(i, "AC").Value = "CRS"
End If
i = i + 1
Wend
End Sub
Sub Macro3()
Dim wsh As Worksheet, Column As Long, lngEndRowInv As Long
Set wsh = ActiveSheet
i = 2
lngEndRowInv = wsh.Range("A" & wsh.Rows.Count).End(xlUp).Row
While i <= lngEndRowInv
If Cells(i, "S") Like "*CUI*" And Cells(i, "T") Like "*CUI-Fund*" Then
Cells(i, "AC").Value = "CUI"
End If
i = i + 1
Wend
End Sub
Sub Macro4()
Dim wsh As Worksheet, Column As Long, lngEndRowInv As Long
Set wsh = ActiveSheet
i = 2
lngEndRowInv = wsh.Range("A" & wsh.Rows.Count).End(xlUp).Row
While i <= lngEndRowInv
If Cells(i, "S") Like "*CRA*" And Cells(i, "T") Like "*CRA Corp*" Then
Cells(i, "AC").Value = "CRA"
End If
i = i + 1
Wend
End Sub
Sub Macro5()
Dim wsh As Worksheet, Column As Long, lngEndRowInv As Long
Set wsh = ActiveSheet
i = 2
lngEndRowInv = wsh.Range("A" & wsh.Rows.Count).End(xlUp).Row
While i <= lngEndRowInv
If Cells(i, "S") Like "*CGC*" Then
Cells(i, "AC").Value = "CGC"
End If
i = i + 1
Wend
End Sub
Sub Macro6()
Dim Hmm As String
Hmm = ("CCP")
If Hmm <> vbNullString Then
For c = 1 To Range("A" & Rows.Count).End(xlUp).Row
If Range("AC" & c).Value = vbNullString Then
Range("AC" & c).Value = Hmm
End If
Next c
End If
End Sub
Sub Macro7()
Dim LR As Range, LR2 As Range
With Sheets("Table")
Set LR = .Cells(.Rows.Count, "A").End(xlUp)
End With
With Sheets("Sheet1")
Set LR2 = .Cells(.Rows.Count, "AC").End(xlUp)
.Range("L2:L" & LR2.Row).Formula = "=IF(ISERROR(MATCH(AC2,Table!$A$2:$A$" & LR.Row & ",0)),"""",VLOOKUP(AC2,Table!$A$2:$F$" & LR.Row & ",2,FALSE))"
End With
End Sub

<colgroup><col width="64" style="width:48pt"> </colgroup><tbody>
</tbody>
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Here you are
all in one
Code:
Sub Macro1()
Dim wsh As Worksheet, Column As Long, lngEndRowInv As Long
Set wsh = ActiveSheet
i = 2
lngEndRowInv = wsh.Range("A" & wsh.Rows.Count).End(xlUp).Row
While i <= lngEndRowInv
'2
If Cells(i, "S") Like "*CRA*" And Cells(i, "T") Like "*CRS*" Then
Cells(i, "AC").Value = "CRS"
End If
'3
If Cells(i, "S") Like "*CUI*" And Cells(i, "T") Like "*CUI-Fund*" Then
Cells(i, "AC").Value = "CUI"
End If
'4
If Cells(i, "S") Like "*CRA*" And Cells(i, "T") Like "*CRA Corp*" Then
Cells(i, "AC").Value = "CRA"
End If
'5
If Cells(i, "S") Like "*CGC*" Then
Cells(i, "AC").Value = "CGC"
End If


i = i + 1
Wend


'6
Dim Hmm As String
Hmm = ("CCP")
If Hmm <> vbNullString Then
For c = 1 To Range("A" & Rows.Count).End(xlUp).Row
If Range("AC" & c).Value = vbNullString Then
Range("AC" & c).Value = Hmm
End If
Next c
End If
'7
Dim LR As Range, LR2 As Range
With Sheets("Table")
Set LR = .Cells(.Rows.Count, "A").End(xlUp)
End With
With Sheets("Sheet1")
Set LR2 = .Cells(.Rows.Count, "AC").End(xlUp)
.Range("L2:L" & LR2.Row).Formula = "=IF(ISERROR(MATCH(AC2,Table!$A$2:$A$" & LR.Row & ",0)),"""",VLOOKUP(AC2,Table!$A$2:$F$" & LR.Row & ",2,FALSE))"
End With


End Sub
 
Upvote 0

Forum statistics

Threads
1,215,494
Messages
6,125,139
Members
449,207
Latest member
VictorSiwiide

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top