473,401 Members | 2,068 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,401 software developers and data experts.

Do While loop resets?

25
I am using VB6.3 out of excel and I have the following section of code:

Expand|Select|Wrap|Line Numbers
  1. Dim rownum As Integer
  2. Dim colnum As Integer
  3. Dim currcell As Range
  4. Dim UnmatchedCount As Integer
  5. Dim CTDate As String
  6.  
  7. If UnmatchedCount > 0 Then
  8.     rownum = Blockrow1
  9.     Set currcell = ActiveSheet.Cells(rownum, colnum)
  10.     colnum = colnum + 1
  11.     CTDate = ActiveSheet.Cells(rownum, colnum).Value
  12.     colnum = colnum - 1
  13.  
  14.     Do While currcell <> ""
  15.  
  16.         If currcell.Interior.ColorIndex = 33 Then
  17.             currcell.Select
  18.             Selection.Delete Shift:=xlUp
  19.             colnum = colnum - 1
  20.             Set currcell = ActiveSheet.Cells(rownum, colnum)
  21.             currcell.Select
  22.             Selection.Delete Shift:=xlUp
  23.             colnum = colnum + 2
  24.             Set currcell = ActiveSheet.Cells(rownum, colnum)
  25.             currcell.Select
  26.             Selection.Delete Shift:=xlUp
  27.             colnum = colnum - 1
  28.         Else
  29.             colnum = colnum + 1
  30.             Set currcell = ActiveSheet.Cells(rownum, colnum)
  31.             currcell = CTDate
  32.             colnum = colnum - 1
  33.             rownum = rownum + 1
  34.         End If
  35.         Set currcell = ActiveSheet.Cells(rownum, colnum)
  36.     Loop
  37. End If
(The variables are set previously in the macro and I have showed the Dims just for reference)

The problem is that when it loops to the top for some reason it is not using the new currcell that it is set to at the bottom. It is using the same currcell that it started with? What am I missing?

Thanks for any input.
Mar 6 '08 #1
3 1254
Killer42
8,435 Expert 8TB
Is it possible you should be leaving out the Set keyword? As in...
Expand|Select|Wrap|Line Numbers
  1. currcell = ActiveSheet.Cells(rownum, colnum)
Note - not telling you, just asking.
Mar 7 '08 #2
if1467
25
Is it possible you should be leaving out the Set keyword? As in...
Expand|Select|Wrap|Line Numbers
  1. currcell = ActiveSheet.Cells(rownum, colnum)
Note - not telling you, just asking.
I tried that and the error "object required" came up. Any other ides?
Mar 10 '08 #3
Killer42
8,435 Expert 8TB
I tried that and the error "object required" came up. Any other ides?
Have you traced through the execution to make sure it's doing exactly what you think? And have you checked that colnum and rownum have the expected values each time around the loop?
Mar 11 '08 #4

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

Similar topics

2
by: Beau E. Cox | last post by:
Hi - I have an application which is essentially 'read-only' - once the database is loaded it is only read from. So, I am trying to implement it with various indices and a table containg some...
3
by: M Katz | last post by:
Hi, I'm using the following to allow dynamic resixing of an image (when the usre presses down on a button): function widthup() { image.width = image.width + 1; width.innerText = image.width;...
15
by: Robin Eidissen | last post by:
What I try to do is to iterate over two variables using template metaprogramming. I've specialized it such that when it reaches the end of a row ot starts on the next and when it reaches the last...
2
by: Loribeth | last post by:
Hi All, I am working on a sub that will loop through a recordset and validate that the ranges are valid, ie no overlapping values - no gaps in the ranges. I am pretty sure I have the validation...
0
by: deanhiller | last post by:
I was using a MessageQueue like so responseQueue.ReceiveByCorrelationId(msg.Id, responseQueueTimeout); It turns out that this sometimes resets the MessageReadPropertyFilter.Body to false, even...
3
by: rengeek33 | last post by:
I have a strange issue: I have a dropdownlist (lstSrchPeriod) that has a SelectedValue of something (say "12"). I use an IF statement to determine if that value is there: If...
18
by: barry | last post by:
I'm having a problem creating a delay before each list item gets moved ( http://www.polisource.com/PublicMisc/list-splitter-timeout-bug.html ). Choose any number of columns, vertical layout, and...
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
4
by: jbott59 | last post by:
I have 10 comboboxes. i would like to run a loop that would reference each combo box and resets certain values. The comboboxes are named ComboBox1, Combobox2, ..... ComboBox10. Here is a sample of...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.