I am trying to show columns with "Register" on the certain cell,
and hide the others without "Register".
Columns 6 to 58 are hidden first
I used the below code, and got part of the result.
Sub Info_Register()
Dim s As Integer
For s = 6 To 58
If Cells(13, s).Value = "Register" Then
Columns(s).Hidden = False
End If
Next s
End Sub
Why I say part of the result, because I always get the Error Type Mismatch on the below part of the code.
If Cells(13, s).Value = "Register" Then
Not sure what type is correct, need help to use the correct type.
Sample Data:
State AL HI CA NY
Status Register Don't register Incomplete Data Register
Name Person A Person B Person C Person D
Contact Number 1234567 6789043 6836281 4267889
Email Address a#xyz.com b#xyz.com c#xyz.com d#xyz.com
One of your variables has a different type, for example integer, and you are testing the variable with a string, that is when you would receive the mismatch error.
On the Menu, at the top of the Window, click on Debug, and Use the Step Into button. You could also use a breakpoint, if you know where the error occurs use the Locals window to know for sure which variable, is the one with the error.
Related
Has anyone been able to get the time-phased work effort VBA extract macro by Jack Dalhgren, its quite an old macro.
I've been able to create the form and the macro works for the default timephase which is weeks, but if I select another say months I get an error on this line of code. (runtime error 13, type mismatch)
Set pTSV = ActiveProject.ProjectSummaryTask.TimeScaleData(tbstart.Value, tbend.Value, , cboxTSUnits.Value)
http://zo-d.com/blog/archives/programming/analyze-microsoft-project-resource-usage-data-in-excel.html
Thank you
The comboBox in the code uses 2 columns, the text and the internal representation which is a number. The code uses predefined constants for it like pjTimescaleWeeks. The call to TimeScaleData expects this number as parameter.
It is likely that you get the text (a String) as result from the comboBox, (eg "Week"), and this causes the Type mismatch.
You can specify that you want the value of the 2nd column as Value from the combobox. You can do this using the VBE form designer, set property BoundColumn to 2, or you can do this in you code:
Sub fillTSUnitsBox()
...
cboxTSUnits.List = myArray
cboxTSUnits.BoundColumn = 1
cboxTSUnits.Value = 3
End Sub
I'm setting up a spreadsheet for multiple users on my team for testing purposes.
The idea is that a spreadsheet gets passed around and any feedback whether it be a pass or fail is noted on the spreadsheet.
I've currently added validation on certain cells which are red until something is filled in by, let's call them the primary tester.
I've added further validation via VBA to check that all red cells have something entered, otherwise the tab colour will turn red.
My problem is that the spreadsheet then gets accessed by the secondary tester then I want the tab to stay red until they have passed or failed the work (again based on cell validation).
So I think I've found a solution whereby the
In a module I've got:
Public Function UserName()
UserName = Environ$("UserName")
End Function
Range("M5").Value = Environ("username")
In another worksheet I've got:
Set myRange3 = ActiveSheet.Range("P21")
If UserName <> Range("M5").Value Then
If UserName = Range("E15").Value Then
If Application.WorksheetFunction.CountA(myRange3) = 0 Then
ActiveWorkbook.ActiveSheet.Tab.Color = vbRed
Else
ActiveWorkbook.ActiveSheet.Tab.Color = xlColorIndexNone
End If
End If
End If
'M5 = Primary tester
'E15 = Secondary tester
I expect the primary tester to have filled in all their requirements, making the tab turn from Red to neutral.
I would then expect the secondary tester to open up the spreadsheet and notice that a tab has been flagged as Red, meaning they need to add their validation of pass/fail for the tab to go neutral.
I have a VBA form which is used to enter data on a sheet. I am currently coding the form so as it will load any data already existing in the sheet back into the form.
For simple text strings it works perfectly.
e.g.
ReqSetup.ReqText = Application.Worksheets("Req Sheet").Range("F11").Value
However, I have some combo boxes, that on the form, when they are selected will enter a number in the corresponding cell.
Fail 1. - Run Time Error 380 - Invalid property value.
ReqSetup.MinPerKgCB = Application.Worksheets("Req Sheet").Range("C27").Value
Fail 2.
Dim MinPerKg As Range
Set MinPerKg = Application.Worksheets("Req Sheet").Range("C27")
ReqSetup.MinPerKgCB = MinPerKg
I'm obviously doing something really simple wrong but I can't work out what it is!!
Kind Regards!
I have some combo boxes, that on the form, when they are selected will
enter a number in the corresponding cell
Then you'd need to do the opposite of your code attempt, i.e.:
Worksheets("Req Sheet").Range("C27").Value = ReqSetup.MinPerKgCB.Value
That you'd better wrap inside a check that any combobox value is actually selected :
With ReqSetup.MinPerKgCB
If .ListIndex <> -1 Then Worksheets("Req Sheet").Range("C27").Value = .Value
End With
I have a table with activated autofilter mode and it is known that only Criteria1-type filtering is applicable (i.e. items of interest are implicitly indicated). My goal is to extract a criteria list for each column in VBA. I used IsArray(.Filters(i).Criteria1) to determine if there is more than 1 item selected for a particular column and everything works fine when either 1 or more than 2 items are selected. However, when I select 2 items, .Filters(i).Criteria1 is not recognized as an array for some reason. .Filters(i).Criteria1 returns only the item that is higher in the list.
Could anyone explain me: why is it so and what is the best way to deal with this problem?
This is an old as question, but in case anyone ends up confused here, confused.
With the a filters object (part of the worksheet.autofilter.filters collection probably)
Here is 1 happens:
1 filter on a column:
filters(i).criteria1 is a string
2 filters on a column:
filters(i).criteria1 is a string
filters(i).criteria2 is a string
3 or more filters on a column:
filters(i).criteria1 is an array of strings (which is a variant)
filters(i).criteria2 doesn't exist
This isn't that clear from MSDN, but it's what happens. My only guess is that in past versions of excel it wasn't possible to add more than 1 filter criteria, and so the old criteria1 and criteria2 types were maintained for backwards compatibility. Still though, it's a stupid system.
Which means that the only way to get the filter properties (as far as I can see) is as follows:
For Each f In ActiveSheet.AutoFilter.Filters
If f.On Then
If IsArray(f.Criteria1) Then
cA = f.Criteria1
Else
c1 = f.Criteria1
On Error Resume Next
c2 = f.Criteria2
On Error GoTo 0
End If
End If
Next
Because Criteria2 errors for both IsEmpty(f.Criteria1) and IsNull(f.Criteria1) so as far as I can see the only way to check if it exists is with an ugly on error resume next
I have a listbox with 3 columns. In some rows there is no entry in the third column (it was never populated). I want to test whether the third column for a particular row has an entry, like this:
if listbox1.list(i,2) = "" then
But this gives a run time error if there is no entry in the third column. I have also tried
if isnull(listbox1.list(i,2)) then
but again this produces a run-time error. I know I can get around this by using on error resume next, but I have a feeling there must be a better way.
Edit:
The error I get is "Could not get the List property. Invalid argument.". In my actual code I refer to .list(i,j) and it works fine when j= 0 and j = 1, but when j = 2 it errors. In the example I am testing there are NO ENTRIES in column 2 of the listbox whatsoever, but the listbox's columncount property is set to a value of 3.
Here are two different ways:
If Len(Me.ListBox1.List(i, 2)) = 0 Then
If IsEmpty(Me.ListBox1.List(i, 2)) Then