I am tring to combine two macros with "ElseIf". both work on their own, however, i keeping getting an error with "ElseIf". My code is - Private Sub Worksheet_Change(ByVal Target As Range)
-
Application.ScreenUpdating = False
-
-
If Target.Address = "$B$1" Then
-
-
Dim ws As Worksheet
-
Dim cWs As Worksheet
-
Set ws = ThisWorkbook.Sheets("test")
-
Set cWs = ThisWorkbook.Sheets("with macro")
-
-
cCol = 0
-
For i = 4 To ws.Range("IV1").End(xlToLeft).Column
-
If ws.Cells(1, i) = Target.Value Then
-
cCol = i
-
Exit For
-
End If
-
Next i
-
-
If cCol <> 1 Then
-
cWs.Range("A5:E100").ClearContents
-
Dim cRow
-
cRow = 5
-
For i = 2 To ws.Range("B65000").End(xlUp).Row
-
If InStr(1, ws.Cells(i, cCol), "yes") = 0 Then
-
cWs.Range("A" & cRow) = ws.Cells(i, 1)
-
cWs.Range("B" & cRow) = ws.Cells(i, 2)
-
cWs.Range("C" & cRow).Formula = "=VLOOKUP(A" & cRow & ",test!$A$1:$BK$25,3,0)"
-
cWs.Range("D" & cRow).Formula = "=VLOOKUP(A" & cRow & ",test!$A$1:$BK$25,MATCH($B$1,test!$A$1:$BK$1,0),0)"
-
cWs.Range("E" & cRow).Formula = "=VLOOKUP(A" & cRow & ",test!$A$1:$BK$25,63,0)"
-
cRow = cRow + 1
-
End If
-
Next i
-
-
For Each i In cWs.Range("C5:E" & cWs.Range("E60000").End(xlUp).Row)
-
If i.Value = 0 Then
-
i.Clear
-
End If
-
-
Next i
-
If cRow = 5 Then cWs.Range("A5") = "NO COMPANIES MISSING DATA"
-
End If
-
-
cWs.Columns("C:E").Select
-
Selection.Copy
-
cWs.Columns("C:E").Select
-
Selection.PasteSpecial PASTE:=xlPasteValues, Operation:=xlNone, SkipBlanks _
-
:=False, Transpose:=False
-
cWs.Columns("C:E").Select
-
Selection.WrapText = True
-
cWs.Range("E6").Select
-
Application.CutCopyMode = False
-
End If
-
-
ElseIf Target.Address = "$B$2" Then
-
-
Dim Rng As Range
-
Dim c As Range
-
Dim MyRange As Range
-
-
Set MyRange = cWs.Range("C5:C" & cWs.Range("C100").End(xlUp).Row)
-
-
Dim rgZeroCells As Range
-
Dim rgCell As Range
-
For Each rgCell In MyRange.Cells
-
If Not IsError(rgCell) Then
-
If rgCell.Value = cWs.Range("$B$2") Then
-
If rgZeroCells Is Nothing Then
-
Set rgZeroCells = rgCell '
-
Else
-
Set rgZeroCells = Union(rgZeroCells, rgCell)
-
End If
-
End If
-
End If
-
Next rgCell
-
If Not rgZeroCells Is Nothing Then
-
rgZeroCells.EntireRow.Delete
-
End If
-
Application.ScreenUpdating = True
-
End If
-
End Sub
1 2400 Luuk 1,047
Expert 1GB
line #52 'end if' should be removed?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: deko |
last post by:
I use this convention frequently:
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case 3163
Resume Next
Case 3376
Resume Next
|
by: p |
last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also
have Crystal 9 pro on my development machine. The web app runs fine on my
dev machine but am having problems deploying....
|
by: developer |
last post by:
Hi All
I have made a .NET project.
the files included are borland c++ files that i am migrate to VC++ .NET
I am using Microsoft Visual C++ .NET 2003.
the compilation goes through properly,...
|
by: f rom |
last post by:
----- Forwarded Message ----
From: Josiah Carlson <jcarlson@uci.edu>
To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org
Sent: Monday, December 4, 2006 10:03:28 PM
Subject: Re: ...
|
by: hyperpau |
last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding.
I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com).
Ergo, I...
|
by: madhu.ab |
last post by:
Hi All,
I am getting the following errors when i am including header file
winuser.h
I dont know whats happening. How will an error occur in winuser.h??
Please help.
\microsoft visual...
|
by: hyperpau |
last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding.
I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com).
Ergo, I...
|
by: yashu0209 |
last post by:
I have an error occurring when i try to compile the program and the error is:
D:\Program Files\visual studio 6.0\MSDev98\MyProjects\GLEnabledView\GLNew.cpp(164) : error C2653: 'CGLEnabledView' :...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |