Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Losing data during transfer


Good morning,

I am really hoping this is going to be my last question on lisboxes.
Anyway, I am trying to transfer data from a listbox to a spreadsheet.
Unfortunately the first entry in the listbox always gets dropped an
the specified cell is blank. (Unless I force the cycle to go one les
than the number of options in the listbox. If I do this, then th
remaining item in the listbox shows up as the selection in the firs
cell.) Anyway, here is my code. Any ideas on what I am doing wron
here. Been trying to figure this out since yesterday afternoon and
am guessing it is something simple...

Private Sub CommandButton5_Click()

Dim number As Integer
Dim xcount As Integer

number = 0
xcount = ListBox2.ListCount

ListBox2.ListIndex = 0

Do While xcount 1

If ListBox2.Selected(i) = True Then
Worksheets("HistoricalFS").Cells(11 + number, 2)
ListBox2.List(i)
ListBox2.RemoveItem (i)

End If
number = number + 1
xcount = xcount - 1

Loop

End Su

--
toocol
-----------------------------------------------------------------------
toocold's Profile: http://www.excelforum.com/member.php...fo&userid=3160
View this thread: http://www.excelforum.com/showthread.php?threadid=52971

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Losing data during transfer

Your loop executes "While xcount 1" - so it does not execute when xcount is
equal to 1. I think you really meant "While xcount =1" (or, equivalently,
"While xcount 0)
--
- K Dales


"toocold" wrote:


Good morning,

I am really hoping this is going to be my last question on lisboxes.
Anyway, I am trying to transfer data from a listbox to a spreadsheet.
Unfortunately the first entry in the listbox always gets dropped and
the specified cell is blank. (Unless I force the cycle to go one less
than the number of options in the listbox. If I do this, then the
remaining item in the listbox shows up as the selection in the first
cell.) Anyway, here is my code. Any ideas on what I am doing wrong
here. Been trying to figure this out since yesterday afternoon and I
am guessing it is something simple...

Private Sub CommandButton5_Click()

Dim number As Integer
Dim xcount As Integer

number = 0
xcount = ListBox2.ListCount

ListBox2.ListIndex = 0

Do While xcount 1

If ListBox2.Selected(i) = True Then
Worksheets("HistoricalFS").Cells(11 + number, 2) =
ListBox2.List(i)
ListBox2.RemoveItem (i)

End If
number = number + 1
xcount = xcount - 1

Loop

End Sub


--
toocold
------------------------------------------------------------------------
toocold's Profile: http://www.excelforum.com/member.php...o&userid=31608
View this thread: http://www.excelforum.com/showthread...hreadid=529717


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Losing data during transfer


Sorry K. Dales, just before I had posted the code I had tried to running
it less one loop to see what was happening. I had originally set the
code with While xcount 0. I have also tried For-Next, offset, etc.
None of these solve the problem.

A weird thing that I have noticed is that it is always B11 that is left
blank. If I change the code to:

Worksheets("HistoricalFS").Cells(10 + number, 2) = ListBox2.List(i)

Whatever was supposed to be placed in B11 ends up being blank. I just
can't figure out what is going on. Any ideas on how to fix the code or
a better way to get the information from the listbox into the specified
worksheet cells is really appreciated!

Cheers,
dw


--
toocold
------------------------------------------------------------------------
toocold's Profile: http://www.excelforum.com/member.php...o&userid=31608
View this thread: http://www.excelforum.com/showthread...hreadid=529717

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to open without losing data? Dave H Excel Discussion (Misc queries) 2 September 23rd 08 06:09 PM
Losing Data Jenny B. Excel Discussion (Misc queries) 2 January 31st 08 06:52 PM
losing data / formatting.. nastech Excel Discussion (Misc queries) 2 January 30th 06 11:40 PM
transfer one worksheet to another worksheet without losing format. TwiztidKitten Excel Worksheet Functions 1 August 18th 05 09:49 PM
Losing data when converting uks5075 Excel Programming 0 June 10th 04 11:05 PM


All times are GMT +1. The time now is 03:54 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"