473,513 Members | 2,358 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error with "ElseIf"

1 New Member
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

Expand|Select|Wrap|Line Numbers
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2.     Application.ScreenUpdating = False
  3.  
  4.     If Target.Address = "$B$1" Then
  5.  
  6.         Dim ws As Worksheet
  7.         Dim cWs As Worksheet
  8.         Set ws = ThisWorkbook.Sheets("test")
  9.         Set cWs = ThisWorkbook.Sheets("with macro")
  10.  
  11.         cCol = 0
  12.         For i = 4 To ws.Range("IV1").End(xlToLeft).Column
  13.             If ws.Cells(1, i) = Target.Value Then
  14.                 cCol = i
  15.                 Exit For
  16.             End If
  17.         Next i
  18.  
  19.         If cCol <> 1 Then
  20.             cWs.Range("A5:E100").ClearContents
  21.             Dim cRow
  22.             cRow = 5
  23.             For i = 2 To ws.Range("B65000").End(xlUp).Row
  24.                 If InStr(1, ws.Cells(i, cCol), "yes") = 0 Then
  25.                     cWs.Range("A" & cRow) = ws.Cells(i, 1)
  26.                     cWs.Range("B" & cRow) = ws.Cells(i, 2)
  27.                     cWs.Range("C" & cRow).Formula = "=VLOOKUP(A" & cRow & ",test!$A$1:$BK$25,3,0)"
  28.                     cWs.Range("D" & cRow).Formula = "=VLOOKUP(A" & cRow & ",test!$A$1:$BK$25,MATCH($B$1,test!$A$1:$BK$1,0),0)"
  29.                     cWs.Range("E" & cRow).Formula = "=VLOOKUP(A" & cRow & ",test!$A$1:$BK$25,63,0)"
  30.                     cRow = cRow + 1
  31.                 End If
  32.             Next i
  33.  
  34.             For Each i In cWs.Range("C5:E" & cWs.Range("E60000").End(xlUp).Row)
  35.                 If i.Value = 0 Then
  36.                     i.Clear
  37.                 End If
  38.  
  39.             Next i
  40.             If cRow = 5 Then cWs.Range("A5") = "NO COMPANIES MISSING DATA"
  41.         End If
  42.  
  43.         cWs.Columns("C:E").Select
  44.         Selection.Copy
  45.         cWs.Columns("C:E").Select
  46.         Selection.PasteSpecial PASTE:=xlPasteValues, Operation:=xlNone, SkipBlanks _
  47.             :=False, Transpose:=False
  48.         cWs.Columns("C:E").Select
  49.         Selection.WrapText = True
  50.         cWs.Range("E6").Select
  51.         Application.CutCopyMode = False
  52.     End If
  53.  
  54.     ElseIf Target.Address = "$B$2" Then
  55.  
  56.         Dim Rng As Range
  57.         Dim c As Range
  58.         Dim MyRange As Range
  59.  
  60.         Set MyRange = cWs.Range("C5:C" & cWs.Range("C100").End(xlUp).Row)
  61.  
  62.         Dim rgZeroCells As Range
  63.         Dim rgCell      As Range
  64.         For Each rgCell In MyRange.Cells
  65.             If Not IsError(rgCell) Then
  66.                 If rgCell.Value = cWs.Range("$B$2") Then
  67.                     If rgZeroCells Is Nothing Then
  68.                         Set rgZeroCells = rgCell '
  69.                     Else
  70.                         Set rgZeroCells = Union(rgZeroCells, rgCell)
  71.                     End If
  72.                 End If
  73.             End If
  74.         Next rgCell
  75.         If Not rgZeroCells Is Nothing Then
  76.             rgZeroCells.EntireRow.Delete
  77.     End If
  78.         Application.ScreenUpdating = True
  79.     End If
  80. End Sub
Nov 28 '14 #1
1 2404
Luuk
1,047 Recognized Expert Top Contributor
line #52 'end if' should be removed?
Nov 28 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

13
6575
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
7
4979
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....
1
3265
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,...
2
5301
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: ...
2
19405
hyperpau
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...
15
5663
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...
0
2897
hyperpau
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...
5
4155
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' :...
0
7267
marktang
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,...
0
7175
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...
0
7391
Oralloy
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,...
0
7553
jinu1996
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...
1
7120
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...
0
5697
agi2029
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,...
0
4754
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...
0
3235
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1609
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 ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.