Code Only Works Every Other Time I Run It

Mar 19, 2007

I am trying to programmatically select an item from a single selection listbox (i.e., set to fmMultiSelectSingle). The following code works properly only every other time I run it; the problem is extremely repeatable.

Const storeStartCell = "B5000"
Private Sub ListBox_CounterTOs_Click()
selectedTOName = CStr(Mid(Worksheets("Sheet1"). Range(storeStartCell).Offset(ListBox_CounterTOs.ListIndex, 0), 3, 3))
selectedTONumber = CInt(Mid(Worksheets("Sheet1").Range(storeStartCell).Offset(ListBox_CounterTOs.ListIndex, 0), 6, 4))
ListBox_TO_Name.Value = selectedTOName
ListBox_TO_Number.Value = selectedTONumber
End Sub

The times that it works, ListBox_TO_Name.Value is set to something like "ABC" and ListBox_TO_Number.Value is set to something like "1234". When the values get set properly, the associated click subroutines (e.g., ListBox_TO_Name_Click()) get called automatically when the value is set. The times that it doesn't work, they are both set to "" and the click subroutines do not get called. I also tried

myListbox.Selected(myIndex) = True

View 4 Replies


ADVERTISEMENT

2002 Code V 97 Code: Add A Small Workbook Open Event Code Which Works For Me But Debugs For The Others

Jan 27, 2009

I use excel 2002 but some of my office are on 97, i want to add a small workbook open event code which works for me but debugs for the others?? The code is basically, go to a tab, on that tab and that range sort..

View 2 Replies View Related

VB Works On One PC, Not On Another (Run-time Error 9 )

Apr 15, 2009

I run PCs at work and at home. Both machines run Windows XP and Office 2007

Home PC: Windows XP Home edition Version 5.1 (Service Pack 3)
Excel 2007 SP1 MSO

Work PC:Windows XP Professional version 5.1 (Service Pack 3)
Excel 2007 SP1 MSO

The VB was created on the home PC. It works. On the Work PC it crashes on the line with bold. Run-time error 9 - Subscript out of range. This have never happened before (or with any other VB routine). I also changed fileNew to include the full path, but same error. What has caused this? I suspect it’s the 'fileNew'.

View 4 Replies View Related

Error Handling - Works First Time But Not The Second?

Feb 26, 2014

I am trying to handle an error. It works the first time but when it runs in the same error again it does not go to the error handling.

[Code].....

View 6 Replies View Related

Right Click Menu Change Works 50% Of Time

Jun 13, 2007

I'm working on a sheet which uses a fair amount of indirects, deleting or adding rows bugger these up, so I wanted to replace them with a macro which does if for them and keeps the structure intact. I've sorted the macro to do this and have sorted the macro to replace delete with my delete in the cell RC menu but the row RC menu only seems to work on around 50% of the PC's? All PC's are XP with XL 2003. The code I've used is detailed below. Is this a known issue with XL or something funky with some of the PC's?

With Application
. CommandBars("Row").Controls("Delete Row").Delete
Application.CommandBars("Row").FindControl(ID:=293).Delete
Set cBut2 = .CommandBars("Row").Controls.Add(Temporary:=True, Before:=6)
End With

With cBut2
.Caption = "Delete Row"
.Style = msoButtonCaption
.OnAction = "Delete_Row"
End With

View 2 Replies View Related

Code Works In One Workbook But Not Another

Feb 19, 2009

This code, supplied through this forum, works perfectly in one workbook but not another. I have created a range called ColourRange, one called ColourIndex but I am getting a '400' error message when I attempt to run it. Can anone explain to me (in very simple terms) why it won't work?

Sub CopyFormatMMT()
'Colour code Owners
Dim r As Range
Dim f As Range
Dim c As Range
Dim j As Range
Set r = Range("ColourRangeMMT")
Set f = Range("ColourIndex")
Range("ColourRangeMMT").Select
Selection.Interior.ColorIndex = xlNone
For Each c In r.Cells
For Each j In f.Cells
If c = j Then
c.Interior.ColorIndex = j.Interior.ColorIndex
End If
Next j
Next c
Range("C9").Select
End Sub

View 2 Replies View Related

Formula Works On Numbers But Not On Time With Format Cell?

Jul 27, 2014

The formula works on numbers but not on time with format cell : [u]:mm:ss

HTML Code: 
8
7
6
11
12

HTML Code: 
8:00:00
8:00:00
6:00:00
3:00:00

[Code]....

View 1 Replies View Related

VBA COde That Works For My Accounting Journal

Apr 22, 2007

I am trying to create this macro for my accounting journal What I want to happen is that in my sheet1 if the 1st cell in column a is "CASH" then the whole row should be copied and pasted in sheet 2. i want this to happen from the first cell in a column until the very last data in column a which means i am not certain up to what row number it will have data since this is a journal with uncertain number of transactions.

View 9 Replies View Related

Small Code Works For One User But Not Another

Oct 5, 2009

This snippet of code works fine when I run it. When another user uses this same workbook and runs it it gives an error:

Sheets("Data").Select
Range("A2").Select
ActiveSheet.Paste
This is the line highlighted by excel:

ActiveSheet.Paste
I have tried changing it to:

Sheets("Data").Paste

View 9 Replies View Related

Activate Workbook Code Only Works On Some PCs

Oct 20, 2007

I wrote code to update some workbooks. The code opens the workbooks and then activates the workbook to add the update.

I was tired when I wrote the code to activate the workbook and it is written:

Workbooks("Update").Activate

The updates have already been sent out and it is not working on some computers. (If I change the code to

Workbooks("Update.xls").Activate

it works fine.)

Is there some option in the VBA editor that I can have people change on their computer so the code will run? Why does it work on some computers and not others?

(Unfortunately, rewriting the code to add ".xls" and resending everything isn't an option.)

View 7 Replies View Related

Code Works In Debug Mode But Will Not Run Through When Played

Mar 13, 2013

I put together about 10 separate macros that will log you into a site using the values in a given cell. I was having trouble with the last one because of AutoComplete remembering the username. So I put in an IF statement, and when I used F8 to go line for line, it works perfectly. However, when I click F5 and just let it play through, it doesn't log in. I tried adding a 5 second delay, but that didn't seem to work. I still get a run-time error when I hit play.

It get hung on this line:

Code:
If doc.getElementById("user_name").Value = cUsername Then

But the complete code is this:

Code:
Sub StreetLinks_Login()
'On Error Resume Next

Dim cURL As String
cURL = Worksheets("Sheet1").Range("B9").Value

[Code] ..........

View 7 Replies View Related

Find Method Code Works Only In Immediate Window

Sep 1, 2006

I am trying to write a function that searches a column for an index then sums the value in a corresponding column. This function works when run in the immediate window of VBA but when I use it in the spreadsheet it can't find any rows.

The reason I need this formula is because there are more than one rows that can be found.

Function SumIndex2(ByVal sField As String, ByVal sIndex As String) As Double

Dim i As Integer
Dim dSum As Double
Dim rng As Range
Dim firstaddress As String

View 5 Replies View Related

VBA Code Works Great Until Number Of Rows Changed

Jan 21, 2014

I wrote the following basic code earlier (which will end up being part of a larger code)

Code:
Dim DateInput As String
Dim LastCell As String

Sub LastRowInputBox()

LastCell = InputBox("What is the last row number in the range?", "Last Row Input")

[Code] ......

As you can see, all the ColumnCopyInsert Subroutine does is copy select/copy four columns (E:H), inserts the copied selection immediately to the right, inserts formulas and autofills down to the last row required. I added the LastRowInputBox routine as the range of rows varies from week to week (inserting new rows, deleting others).

The code works great...up to a point unfortunately. If ran as it is, everything that should be copied/pasted will be and cells autofilled to the row specified via the InputBox. Here comes the problem, if any rows are either inserted or deleted then the code throws out "The object invoked has disconnected from its clients" when it reaches the first instance of the following line:

Code:
Selection.Insert Shift:=xlToRight

At which point, Excel hangs (or maybe in some sort of loop) and I have to open Device Manager and close the Excel exe process.

View 5 Replies View Related

Macro Code Only Works If Specific Worksheet Active

Apr 30, 2008

I have searched the FAQ's but have not found a suitable answer to my problem. I have some code that works perfectly when it is run from the VB Editor but when I put it behind a command button it gives me an error almost straight away. I have read that when a command button is used the command button defaults the active sheet to the one that it is one therefore you always have to specify the active sheet but I have done this so am still confused as to why it is falling over. Below is my code, I have commented where it is tripping:

Sub FormattingAcutalReport()
Workbooks.Open Filename:="H:Risk ReportingDaily TemplatesMF Consolidated Risk DAILY LIVE DATA FROM BO.xls"
Workbooks.Open Filename:="H:Risk ReportingDaily TemplatesDaily Non Banks LIVE.xls"
Dim myBorders() As Variant, item As Variant
Set SEGNSEG = Workbooks("Todays Reports.xls").Worksheets("Seg and Non Seg Bank Summary")............................

View 2 Replies View Related

Code To Find And Offset Works On First Sheet But Won't Loop To Other Sheets

Mar 5, 2009

I have this code attached to a button on the first sheet of a workbook with hundreds of sheets.

it is suposed to look for a cell that contains "SAY:" and then move one column to the right and make it a zero. It works on the first sheet but not on any other sheet.

View 7 Replies View Related

Excel Code Works Fine But Error When Called From Access?

Apr 11, 2012

This code works fine when I run it in Excel.

Code:

Sub RemoveCodeAndSave()
'Remove all code from ThisWorkbook code module
ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule.DeleteLines 1, _

[Code]....

I get the error "Run-time error 440: The specified dimension is not valid for the current chart type" why I am getting this. The macro does everything I want it to, except for throwing the error at the end.

View 3 Replies View Related

Adding Time: Adding Individual Cells Works, But SUM Doesn't

Mar 28, 2008

I have a column of times: e.g. 10:03:00 and I would like to add them all up.

=A1+A2 works fine.

=sum(A1:A10) does not.

View 14 Replies View Related

Unzip Code - Works Without Variables, Breaks With Variables...

Feb 5, 2009

Unzip Code - Works without Variables, Breaks with Variables.... This has been driving me bananas...

I have the

View 2 Replies View Related

VBA Code To See SUM And AVERAGE At The Same Time

May 2, 2007

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range
Set rng = ActiveCell.CurrentRegion
Application.StatusBar = _
"Current SUM is: " & _
Application.WorksheetFunction.Sum(rng) & " " & _
"Current AVERAGE is: " & _
Application.WorksheetFunction.Average(rng)
End Sub

I now have the following problems:

I get a errot when i select cells with no number

Run-time error 1004
Unable to get Average property of the WorksheetFunction class

The sum and average stay in the status bar.

The code gets confused after i selected different columns.

I would like the code to work only when i select a range of cells.

Is it possible to move the text in the status bar more to the right?

View 9 Replies View Related

Stop Code After Certain Time

Jun 14, 2008

Trying to get my code to loop for one minute. Have tried this code (after searching through a few threads):

Sub LoopUsingTime()
x = 1
EndTime = Now + TimeValue("00:01:00")
For lCount = Now() To EndTime
Sheet1. Cells(x, 1) = "the time is now " & Now()
Sleep 5000
x = x + 1
Next lCount
MsgBox ("loop finished")
End Sub

View 2 Replies View Related

Time Code Calculator 30fps - Mac

May 20, 2009

I found this great formula posted on this site for calculating time code @ 24fps:

=TEXT(LEFT(B2,8)-LEFT(A2,8)-(RIGHT(A2,2)>RIGHT(B2,2))/86400,"m:ss")&TEXT(MOD(RIGHT(B2,2)-RIGHT(A2,2),24),":00")

Can anyone tell me how to change it for 30fps? I'm using Excel 2008 for Mac, so I'd rather use a formula than figure how to make VBA work on Macs.

View 7 Replies View Related

Time Limit On Code Execution

Jul 8, 2009

I have a function which will allow me to search for combination of numbers which will sum to zero. However, because the range could be as long as 300 rows or even the possibility of not finding the combination that will sum to zero, the macro will take ages to complete or even causes the whole excel to hang. So What i want is to instruct macro to stop doing the search if it cannot find the results after say 20 minutes of searching.

Is that possible?

View 14 Replies View Related

Time Code Data Formatting

Oct 16, 2006

I am working on some data cleanup for some video. I have a lot of time code data, ie. mm:ss (minutes; seconds), and I need to convert it to hh:mm:ss:ff (hhi is hours; ff is frames). It's A LOT of data, and I don't want to do it by hand.

Examples:

2:02
0:55
2:18
2:55
1:41
1:20
1:44

I have two quesxtion:

1. Excel wants to interpret my data as time data and will convert my data if I click on a cell, ie. 2:02 is converted to 2:02:00 AM. That might not be so bad, but sometimes it changes a time that is 00:55 to 12:55:00. So, my first question is...how do I make excel read the numbers exactly as is w/o any conversion? I've tried to mark the cells as Text but that doesn't work, and I can't seem to make a Custom format work. Any ideas?

2. Ideally, I'd like to quickly convert these timecodes to hh:mm:ss:ff. Would macro work on this? So, I'd be taking 2:02 and making it 00:02:02:00. I think I need to solve #1 before I tackle #2, but i could be wrong.

View 10 Replies View Related

Code To Select More Than One Range At A Time?

Feb 1, 2012

I thought i would create some code to highlight a batch of cells so i can modify formatting all together rather than cell by cell

I am unable to get the generated code to select all ranges together, it only shows the last range

Here is my code

Code:
Sub SelectRanges()
'
' Macro1 Macro
'
'
Range("D12:H12").Select

[Code]....

View 7 Replies View Related

Code To Calculate Total Time

Nov 27, 2013

I have a form which captures below details.

Label 1 = Time when form initialized or opened
Label 2 = Running Time (Live Time)
Label 3 = Total Time (Label 2 - Label 1)

Now what I need is since Label 2 is live time which shows the running time, Label 3 displays the total time spent. I want to display total time as running time.

e.g.
Label 1 = 13:01:00
Label 2 = 13:05:10 (running time/live time) which will keep ticking
Label 3 = 00:04:10 (I want even this as running time which keep running when label 2 is running)

View 1 Replies View Related

VBA Code Run-time Error '1004'

Jan 14, 2010

Sub paste()

' paste Macro
' Macro recorded 2/20/2009 by lawryad

Range("A" & Rows.Count).End(xlUp).Offset(1).Select
ActiveSheet.paste
ActiveSheet.paste
Application.CutCopyMode = False
ActiveSheet.Range("p1").Copy
ActiveSheet.Range("a1").Select
End Sub
Now everything works good with this code unless there is nothing copied to paste. In that case it will go to a "run-time error'1004' " I would like instead for a msg box to appear saying "You must copy required data first"

View 9 Replies View Related

Format Time From Cell In VBA Code

Apr 1, 2009

I am trying to insert data from an excel sheet to a sql database. Everything works okay but the Time value. In the Excel sheet it is '12:09 PM' and when it is read with 'cl. Offset(0, 6).Value' it turns it into '0.50625'. Is there a way to format it so it can be inserted as a datetime?

Dim cl As Range
For Each cl In Range("A1:A12")
stSql = "INSERT INTO GasData (Delivery,OpenPrice,High,Low,Last,Change,Time) VALUES ('" & _
cl.Value & "','" & _
cl.Offset(0, 1).Value & "','" & _
cl.Offset(0, 2).Value & "','" & _
cl.Offset(0, 3).Value & "','" & _
cl.Offset(0, 4).Value & "','" & _
cl.Offset(0, 5).Value & "','" & _
cl.Offset(0, 6).Value & "')"
cn.Execute stSql
Next

View 2 Replies View Related

Adding Worksheet Code During Run-time

Sep 10, 2004

A procedure residing in the "ThisWorkbook" module has just added a new worksheet into the active workbook. I now want this same procedure to write a set of code into this new sheet's code module.

Solution 1:
Create a worksheet before run-time that is already set up with the code you want behind it. Then, use this worksheet as a sort of "template" when you want to create a new worksheet as opposed to using the worksheet.add method.

Question:
I can use solution 1, but isn't there a way to insert the code on the fly?

View 6 Replies View Related

Converting Time Code To Seconds

May 21, 2006

I have very little experience with Excel. What I am trying to do is to convert a timecode in this format 00;22;21;00 that is 22 min 21 sec and 00 frames to a serie of numbers that I have hard time to figure out. Example

00;22;21;00 = 13410000000

I want to be able to paste the timecode from premiere 2.0 (00;22;21;00) into a Excel cell that would automaticly convert it to (13410000000) so that i can eventualy generate a .txt file that would look like this:

<Scripts >
<Script Type="URL"
Command="http://www.softfx.com/slide01"
Time="13410000000" />
</Scripts>

View 2 Replies View Related

Adding Code To A Userform At Run-time

May 27, 2007

The ultimate goal is to create a Userform at run-time.

The problem is writing event code for that Userform.

The current situation is:
I have a userform. (Created with the VBE, not at run-time.) There is one command button on that userform. The code module for that userform is this

Option Explicit ...

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved