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 2404 Luuk 1,047
Recognized Expert Top Contributor
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: 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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |