473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

error with "ElseIf"

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 2400
Luuk
1,047 Expert 1GB
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
0
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...
0
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
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
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
tracyyun
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...
0
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,...

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.