Using .Autofilter , using results in Textbox.value - vba

Im using .autofilter to filter a list in excel, my problem is i want to have the results from the autofilter populate textboxes. i know i can use something similar to
textbox.text = Data(a1).value
however as the cells are filtered they keep there original cell location so i cant just use the cell location. There will only ever be one result to the filter so i need something that populates the text boxes from the row just under the filter heading.
for back ground the over all idea is to have a spread sheet that can be searched from a userform, which currently works, and then display the results in text boxes. Keeping the user of the spreadsheet away from the raw data as possible.

Maybe the function SpecialCells(xlCellTypeVisible) can help you... Your code could look like this:
Sheet1.Range.SpecialCells(xlCellTypeVisible).Cells(1,1).Value
I haven't tried it...

If you only will ever have 1 result, the following works:
textbox.text = Sheet1.Range("myrange").SpecialCells(xlCellTypeVisible).Value
but you will get a type mismatch if there is more than 1 result in the filter.

Related

SUMIFS returns 0 using dynamic criteria, with criteria range and sum range on another sheet

Anyone,
I've chatted with and called excel customer service with no luck. I used the formula builder (please see attached screenshot) to make sure each element of the formula is correct and returns the value for the criteria I'm trying to reference.
Everything is accurate, but it returns a value of 0. When I do the same thing in the actual sheet the data is stored in (and click a criteria cell within the criteria range) it returns the accurate value?! I'm not sure why it won't work on the other sheet. The values I am using to select are dynamic and change with a drop down. I have another, advanced, workbook (I did not create) that does the same thing and completes an even more complicated formula, but actually works so I'm not sure why this is returning a 0 value.
Photos and code/syntax: Dynamic Selection, Example 2 of it working, Example 1 of it working, Formula Builder, CountIFs, Advanced Spreadsheet working, VLOOKUP
=SUMIFS('GFEBS Pull'!Q:Q,'GFEBS Pull'!G:G,FMCOP!$C$20,'GFEBS Pull'!H:H,FMCOP!B23)
or:
=SUMIFS('GFEBS Pull'!Q:Q,'GFEBS Pull'!G:G,'FMCOP'!$C$20,'GFEBS Pull'!H:H,'FMCOP'!B23)
When I type ' around FMCOP sheet name, they disappear? I've also tried to lock the columns on the 'GFEBS Pull' sheet with no luck. Cell B23 is not locked because I'm going to copy the formula down to reference other cells. Any help is appreciated!
In this screenshot you can clearly see that both FMCOP!C20 ansd FMCOP!B23 have prefacing spaces; e.g. " HHC".
Since " HHC" will never match "HHC", fix the data returned from 'the lower table in the same screenshot'.
A Text-to-Columns, Fixed Width, Finish should do this. You could adjust the original formula like,
=SUMIFS('GFEBS Pull'!Q:Q, 'GFEBS Pull'!G:G, TRIM(FMCOP!$C$20), 'GFEBS Pull'!H:H, TRIM(FMCOP!B23))
I would caution against the latter 'bandaid' fix. Fix the original data; do not apply bandaids on-the-fly.

Advanced filter error

I am trying to create a unique list but the first value in the list is a blank and that seems to be causing me a problem. When I use a basic advanced filter it essentially just names the range 'Extract' and copies the formatting. So F2 equals `Extract' as below,
I have tried many approaches using the criteria range but nothing seems to works. Ideally I want this to be VBA code but the manual Advanced Filter is not working. To clarify I am searching like this,
I see a similar question here, it's just not working for me. Does anyone have any ideas what I am doing wrong? Is it the 'Copy into new location' option that is messing this up? Ideally I need it to be unique fields but I seem to be getting the same results, with or without the unique fields only box ticked.
Eventually I want this to be the code but, when I run the below in VBA I get a Run-Time error.
Range("E2:E5").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _
"h1:h2"), CopyToRange:=Range("F2"), Unique:=True
EDIT
Use <> for the criteria to exclude blanks.
btw, your List Range should be E1:E5 and H1 should be Offset values. Advanced Filters require a header.

with a VBA userform, how do you populate a combobox with a different text and value?

I am trying to populate a VBA userform combobox with a named range, and I want the text value to display in the combobox for the user to select, but the value I want returned is the cell reference to the initial named range. That way it would point back to the named range, and if I change that text, it would automatically update all the references I have on the sheet that were entered by the form.
Right now I can get the named range to populate the combobox by iterating through the range, and using an .AddItem to give it the textual value, but then it just dumps that textual value into my spreadsheet, when instead I would like it to have the cell reference from the range that populated it.
The easiest way to do this is to create an Array(X,2) X being the number of items in the array. Then you put the String you want to display in Array(1,1) and the data you want in Array(1,2) then simply populate the combo box like normal. When you and use the array to reference which item they choose. They choose item 8, you know it is Array(8,2) If you need more help please post some code.
So, after more research it would seem that I am unable to directly accomplish what I want with the combobox. I ended up just looping through the range to fill the combobox with the textual values, and then when I submit the form, I looped through the same range of values, checked it if the submitted value matches one from the range of values, and if it does, then return the .Address instead of the .Value, and that gave me the cell reference I was looking for. Too bad the combobox doesn't work more like a real html select menu, it would have made my life a little easier, but in the end I was able to make it work, it just isn't as clean as I would have liked.

Excel, VB form with Text boxes. On button click. Create new row in worksheet with data from text boxes

Ive been looking around EVERYWHERE! And nothing works. ever.
I would like to be able to have a form that you fill in ( Lets say with two textboxes2 )
When you click the button it should then add a new row below all other populated rows and put the data of the text boxes into the cells of that row.
Nothing I do works :(
Does anyone have any ideas?
My form has:
Textbox1
Textbox2
Worksheet is called Sheet1
( Ive left everything default while testing )
Any help would be epic..
Once I have this bit sorted, i can then modify to do what i want to achieve in the long run. but this basic " Add a row with some data" is just killing me.. It cant be that hard right?
Thanks
G
I believe you could follow a logic similar to that : (After the click)
Find the last populated row
Insert an empty row under it
Grab the data from the textboxes and copy them to their proper column
Does that help? If not, what part are you having trouble? I'll be happy to provide more help.
Something like this could get you started. This assumes your first text box will fill in column A and second text box fills in column B.
Sub InsertText()
Range("A65000").End(xlUp).Offset(1, 0).Select
ActiveCell.Value = TextBox1.Value
ActiveCell.Offset(0, 1).Value = TextBox2.Value
End Sub
I don't think you need to add another row if you're just filling in below the last populated cell. If so
ActiveCell.EntireRow.Insert

Take Textbox input and move to a specific cell.

I'm writing a macro to pull various data from an Excel sheet and put it in a more usable order. A problem I've run into is that one section of the data I want is contained in a textbox. I'd like to pull the data out of the textbox and have it all pasted into a cell, A100.
The textbox is always called ActivityA.
try this
Cells(100, 1) = ActiveSheet.Shapes("NameOfYourTextBox").DrawingObject.Text