Find the next blank column on specific ROW with VBA - vba

I need some help I need to find the next blank column on specific row because my table has some headers and blank spaces on the bottom i try a lot of methods and doesn't work for me
I need to find the next blank column on the row number 5.

Sheet3.Cells(4, Sheet3.Columns.Count).End(xlToLeft)
specifies the first blank cell in row 4 of Sheet3.

Related

Copy and Paste to Blank Rows until Blank in Other Column

I am trying to copy and paste A8:P8 in to the Blank Rows (as per pic below) until the data in column Q is blank - is there a VBA which can do this? I need to do this on multiple tabs so the row number will be variable.
Although you could accomplish this with VBA, have you tried just using cell formulae?
For example, in the first empty cell in column A you'd put:
=$A$8
then the same for each other cell in the row, changing the column letter.
Then select all of the cells with formula and double-clicking the autofill handle which will copy the formula down to the last row with data in the adjacent column.

Find first non-blank cell in column that meets criteria in another column

I've compiled multiple spreadsheets containing sporadic employee information, and I'm now trying to consolidate all of the information to remove duplicates and blanks. The formula below is my starting point, but if the first cell that meets that criteria is blank, it returns a blank. I want it to find the next cell that meets that criteria but has a value.
=INDEX(Working!C:C,MATCH($A3,Working!$B:$B,0))
Below is what the Working tab looks like, which contains the master list of data including blanks and duplicates. Working!C:C is the list of last names; $A3 is the Employee ID I'm hoping to retrieve data for, and Working!$B:$B is the list of Employee IDs. I'll be doing this for many columns, so to illustrate this, in the table example below I've shown that Column D is the phone number. Any help you can provide is appreciated!
Column B-------C-------D
---------287-----Doe----blank
---------287-----blank---333-333-3333
---------287-----Doe----blank
Use the following array formula:
=INDEX(Working!C$1:C$100,MATCH(1,($A3 = Working!$B$1:$B$100)*(Working!C$1:C$100<>""),0))
Being an array formula it needs to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode. If done correctly then Excel will put {} around the formula.
Please note that with an array formula the references need to be the smallest range possible that covers the dataset.

How to avoid adding a new row to the first row of subtotaled ranges to protect Subtotal formula

I have a Excel sheet, which includes many groups and subgroups. Each subgroup has their own subtotal. And as long as I can't know how many lines users will require for the subgroups, I only left 3 rows blank for each subgroup and created a button which triggers Automatically Copy and Insert Copied Row macro.
Now I need to avoid users to trigger the button while they are on the First and the Last row of any subgroup. (If you copy and insert first row, subtotal formula doesn't recognise the new added line because it will be out of the range and Last row has another specific formulas which I don't want users to copy above)
I've been searching SO and the other Excel blogs for a long time but because of my list is very dynamic and have many different subtotals none of them was suitable to my case.
How can I define all of the first and last rows of my different subtotal ranges (and maybe their Title's rows) to avoid them being copied and then inserted above?
I can imagine 2 ways to do this. When the "New Row" button is pressed check if the current row is a headline/subheadline whatever …
by checking its format (eg specific background color etc).
If Not Worksheets("Sheet1").Range("A" & iRow).Interior.Color = 15004911 Then
'copy that row
End If
or by using an extra helper column that specifies the rows as header rows or non copyable rows. If you don't want the helper column to be seen you can hide it.
If Not Worksheets("Sheet1").Range("X" & iRow).Value = "Header" Then
'copy that row
End If
'where X is the helper column
And if it is a headline row then deny the copy process.
One way that doesn't involve programming have your sum range extend into rows that won't change. So you could start the subtotal in the header row (assuming there is no content in the relevant cell in that row). Another way is to have a hidden row at the top and bottom of each sum range and that is included in the sum range. So you would sum rows 10 to 14, but 10 and 14 would be hidden (and empty) and the user would just get shown rows 11, 12 and 13. Adding a new row would push the hidden rows down and extend the subtotal.
Another way is to use the indirect function.
Say your formula was
=SUBTOTAL(9,H7:H10)
If you use indirect for the lower bound, it will always refer to the cell immediately above, regardless of how many rows are added in between.
=SUBTOTAL(9,H7:INDIRECT("H"&ROW()-1))
And taking it one step further, use the upper title row as the anchor to always add up the gap between the title and the subtotal.
=SUBTOTAL(9,INDIRECT("H"&ROW(H6)+1):INDIRECT("H"&ROW()-1))

Vba select entire colum only used range

Does anyone know how to select entire column but only used cells.
Normally the data is continuous. One issue is that sometimes the sheet is filled only for two rows sometimes for hundreds.
What I need to obtain is to loop for all the files in the folder and copy recognized columns only with data. I cannot have selection of entire column because while pasting one below previous macro will throw an error due to range area not fitting.
The source data begins in different rows. Once it starts in second row the other time in third. There are no headers.
I know this is old, but this is an easy way to select the data in a specific column and move it to a new location. It will remove all blanks in the range.
Columns("E:E").SpecialCells(xlCellTypeConstants).Copy Destination: = ActiveSheet.Range("F1")
MaxRow = Range("E" & Rows.Count).End(xlUp).Row
Range("E1:E" & MaxRow).Select
Where E is your Column

How to count Blanks in N'th column in a ListObject table

I want to count Empty cells (Blanks) in the fourth column only. I tried the following code.
ActiveSheet.ListObjects(1).ListColumns(4).DataBodyRange.SpecialCells(xlCellTypeBlanks).Count
In my case, I have a table with only one row and 4'th column has non-empty cell. I get the wrong value with my code. The code above returns 3 Blanks instead of zero - 3 blanks could be total number of blanks in table.
I do not know the specifics behind this bug but it seems closely related to a behavior that used to show up when you tried to reference the visible cells below the header in an AutoFilter range when the filtered range showed no visible cells. In that case, it returned all non-visible rows. While not completely the same, this miscount seems closely related. To the best of my knowledge, that bug has been corrected in Office service packs.
Use the Excel Application object to call a worksheet's COUNTBLANK function to achieve the correct result.
With Worksheets("Sheet1")
Debug.Print Application.CountBlank(.ListObjects(1).ListColumns(4).DataBodyRange)
End With