attaching your spreadsheet would be helpful! (remove all sensitive data)
Posts by rabsofty
-
-
Try this:
Codepos = InStr(1, Cells(1, 2), "/", vbTextCompare) Cells(1, 2).Characters(Start:=pos + 2).Font.Color = -16776961
the instr finds the position of the / character
the next line uses the pos # + 2 as its start to the end of linenote: if you wish only parts of it you can add the length to the characters command
eg:Cells(1, 2).Characters(Start:= a number, Length=: a number).Font.Color = -16776961
-
please provide your spread sheet.
-
whats the error?
-
-
-
after much playing around with this, it seems that if you assign a single range to a listbox you cannot reassign it again as a 2d array.
object.clear does not reset this. -
I originally had code to list some commands (sub lst_dbcmd1)
I called sub lst_dbcmd1 and lst_dbcmd3 after it. (and it works)I decided to change sub lst_dbcmd1 to range list instead of a for loop (range list sub = lst_dbcmd2)
When I call lst_dbcmd2 (has range list) then call lst_dbcmd3 it now fails (could not set list property value)
I have attached a workbook with my problem.
Instructions:
Click the Mod1 button,
Then type cmd1 in the textbox (click OK) - list shown
Then type cmd3 in the textbox (click OK) - list shownboth will work!
Now
Then type cmd2 in the textbox - list shown
Then type cmd3 in the textbox - list failscmd3 fails with listbox property error.
the only change made was cmd1 loads the listbox with a for loop list
cmd2 loads the listbox as a range listFor some reason when you load the listbox with a range list then rebuild it with a 2d array it fails???
If you load it with a for loop then rebuild with a 2d array it works.Code
Display MorePrivate Sub lst_dbcmd1() 'list cmds without range list For x = 1 To 3: InitLB.AddItem Sheet2.Cells(x, 2): Next x End Sub Private Sub lst_dbcmd2() 'list cmds with range list InitLB.List = Range(Sheet2.Cells(1, 2), Sheet2.Cells(3, 2)).Value End Sub Private Sub lst_dbcmd3() 'show list in col 4 and 5 as 2d array For x = 1 To 4: InitLB.AddItem Sheet2.Cells(x, 4): InitLB.List(InitLB.ListCount - 1, 1) = Sheet2.Cells(x, 5).Text: Next x End Sub
-
-
-
In File,Options,Advanced,
change the setting: After Pressing Selection move selection
down -
you can clear out the combobox before adding the new data
Code
Display Morecbb2.clear For i = 2 To Lr cbb2.Value = "" If cbb1.Value = "400" Then cbb2.AddItem Sheets("Level_4").Cells(i, "C").Value ElseIf cbb1.Value = "500" Then cbb2.AddItem Sheets("500").Cells(i, "C").Value ElseIf cbb1.Value = "600L" Then cbb2.AddItem Sheets("600").Cells(i, "C").Value End If Next i
-
use the Val command, it returns zero automatically when the textbox=""
CodeCells(emptyRow, 9).Value = Val(CInt(Me.TextBox8.Value)) + Val(CInt(Me.TextBox9.Value)) + Val(CInt(Me.TextBox10.Value))
Note: Val also returns Zero if the textbox contains a character.
your code should test if user entered characters instead of numbers before you perform the addition.
CodeIf Me.TextBox8.Value = "" Then Me.TextBox8.Value = 0 If Me.TextBox9.Value = "" Then Me.TextBox9.Value = 0 If Me.TextBox10.Value = "" Then Me.TextBox10.Value = 0 If Not IsNumeric(Me.TextBox8.Value) Or Not IsNumeric(Me.TextBox9.Value) Or Not IsNumeric(Me.TextBox10.Value) Then 'report error here Else Cells(emptyRow, 9).Value = Val(CInt(Me.TextBox8.Value)) + Val(CInt(Me.TextBox9.Value)) + Val(CInt(Me.TextBox10.Value)) End If endif
-
There are a lot of different ways to do this, dependant on how many spreadsheets you have.
1. save workbook b4 a), make changes, test - if errors then revert to the saved workbook, (reenter your macro code)2. export your sheets, make changes,test - if errors then reimport exported sheets
3. create routine to save data to files, create routine to format sheets to what you require,
make changes to code - if errors, run macro to reload data and reformat sheets.Personally, I use #1 all the time. (doing it this way for 15yrs)
My spreadsheet loads all data and saves all data from/to files. My loader routine always reformats the data.I have production(Prod) and development(Dev) folders.
the production folders contain current working data and workbook.when I want to work on the workbook, I copy the Prod folder data and workbook to Dev
I then make changes to the code in (Dev) (if the changes are large I open an notepad file and paste the changes to it)
I test the code, if it fails and I have to restore the data, I simply copy the Prod data to Dev and reload it.
if the changes are to great and I want to start over, I copy the Prod workbook and data back to Dev and start over
(if I put code into notepad, I can simply paste the code I want back to the Dev workbook)By doing this production data and workbook remain always remain functional.
As I said this is how I would do it. My financial work is extensive so it works best for me to do it this way. -
there is an error in your if statement.
try this:
CodeIf Weekday(Date) = 1 Then ActiveWorkbook.SaveAs Filename:= _ "C:\Users\bill_\Desktop\DATE TEST - " & Format(Now() - 7, "mm.dd.yyyy") & ".xlsx", FileFormat:=51, CreateBackup:=False Else ActiveWorkbook.SaveAs Filename:= _ "C:\Users\bill_\Desktop\DATE TEST - " & Format(Now() - 1, "mm.dd.yyyy") & ".xlsx", FileFormat:=51, CreateBackup:=False End If
or to save a little code, try
-
I tried your code in Excel2010 and it works the way it supposed to.
-
KjBox, you are right you cannot change a tag at run time. (learned something new)
-
I thought of a way (kinda)
You could put the column#'s in the objects tag field (label names would not change or you can give them a name)
eg:
labelx21 tag = 22 (col#)
combobox21 tag = 22
textbox21 = 22Then when you add a column, you can run a piece of code to change all tags.
-
I can't think of a way to do it at runtime!
-
from what I see you use the label caption to access the information in detemp.
if you add a column, it still uses the labels name to access the data.
So if I read you right, you want the label# to always reflect the column#?