I have an excel sheet with data. I have some VBA that will filter the sheet to a specific value and then move down to the last filled cell.
ActiveSheet.Range("$S$2:$S$1218").AutoFilter Field:=1, Criteria1:= _
"Scheduled"
ActiveSheet.Cells(ActiveSheet.Rows.Count, Selection.Column).End(xlUp).Select
This works fine for the purpose. However, column A has numbers filled out past where I want it to stop. Could this be edited to only query column F (for example) and move down to the last filled cell in column F.
Thank you!
In vba coding, cells are typically denoted as cells(i,j) where i represents the number of row while j represents the number of column.
Since you want to work on column F, which is column no 6, you just have to change the code accordingly like this:
ActiveSheet.Cells(ActiveSheet.Rows.Count, 6).End(xlUp).Select
Related
I have a table in Excel like such, where the number of rows will vary each day:
Column A
Column B
Column C
Cell 1
Cell 2
Show
Cell 3
Cell 4
Show
Cell 5
Cell 6
Ignore
I am using vba to convert the range to a html table, and then email it.
I have a helper column (Column C), and I want to use a formula there to filter out certain rows.
However, that filter is not excluding hidden cells from being displayed in the html table.
I currently use this
Dim LastRow As Long LastRow = rInput.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
to find the last row of my table. This works great in projects where you want all of the table included.
I tried to change it to Find("Ignore", which gets me Object variable or With block variable not set
I tried including 'SpecialCells(xlCellTypeVisible)' in my
ConvertRangeToHTMLTable(Sheet2.Range("$A:$J").Rows("5:" & LastRow), 5)
and using a filter to hide the 'Ignore' cells. But that did not stop them showing in the emailed html table.
You probably have some sort of loop which goes over the rows right? It will not automatically skip the hidden rows just because they are filtered out, you need to specifically tell it to skip them. You can do something like:
For Each r In myRange.Rows
If Not r.EntireRow.Hidden Then
doSomething
End If
Next r
Ended up adjusting the table (and thus the range I cared about) to start at row 1 rather than row 5, and using
strBody = dsaEmailHeader & ConvertRangeToHTMLTable(Sheet2.Range("$A:$H").Rows("1:" & LastRow).SpecialCells(xlCellTypeVisible))
worked, where it didn't previously.
I need to copy a column of data to another column on a different worksheet, pasting values only. The appropriate paste column is identified in a single cell. This cell will be changed manually each time the macro is applied. So one time I might want to copy/paste in the first column, so my identifier cell is 1. The next time I might input 5 in this cell so that I offset 5 columns to the right to copy/paste data. Thank you.
You can reference the columns in a worksheet using the Columns property. You can achieve what I think you're trying to do with code like this.
Dim col As Integer
col = SomeSheet.Cells(1,1).Value
FromSheet.Columns(col).copy
ToSheet.Columns(col).PasteSpecial xlPasteValues
Can I make a VBA that selects all filtered cells of a column and adds a value to the next column to the right?
I.e., I have a list of workers and their current overtime in hours (column L).
I want to filter Column L to >10, and then inserts a "1" in each cell that is shown of column M (so I get a "1" for everyone who worked more than 10 hours of overtime).
Currently I have
Selection.AutoFilter
ActiveSheet.Range("A1").AutoFilter Field:=12, Criteria1:=">10", _
Operator:=xlAnd
which does the filter-part, but I'm at a loss of how to then select the cells in column M and insert a value into them.
Very thankful for any help.
Selection.SpecialCells(xlCellTypeVisible).Offset(,1).Value = 1
Btw you almost always don’t need any selection and can more safely use fully qualified (up to worksheet object) range references
I have inherited a poorly designed workbook, and I am trying to make it work a bit better without starting from scratch.
The last problem I have is that I have a formula in a column that I need to copy to the next column, but change the row number referenced in the formula. The easiest thing to do would be to change the format of the workbook but that will cause an uprising by the users.
=IF((CommaSeparatedListContains(RTM!$I$8,ROW()-2))=TRUE,"X","")
The code above is what I need to copy, but I need to change it so that it looks at I9 instead of I8. RTM is the name of the sheet that the cell is on, and CommaSeparatedListContains is a macro that will return true if the referenced cell has a value (ROW()-2) in the comma delimited list.
Basically I need a macro to add a new column to the worksheet that works like the others, so that the end users who don't know how to use Excel can just click a button and add a column.
For example, that code is in cell A1, and I need to move it to B1 keeping the I the same but increment the row number. If I remove Both $ signs it would change it to J8, if I have $I8 it stays I8, and if I have $I$8 it stays I8.
Thanks for re-affirming my understanding. I'll give this a shot with providing some code, based on your string:
Dim LC as Long, i as Integer
Columns(9).Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Cells(1,10).Value="" 'Add your header
LC = Cells(1, Columns.Count).End(xlToLeft).Column
i = LC-1 'See description below code
Range("J2:J100").Formula="=IF((CommaSeparatedListContains(RTM!$I$" & i & ",ROW()-2))=TRUE,""X"","""")"
For i, you want to ensure that you substract the correct number... given the example of I8 being the cell you want to reference, and assuming that Column I is the last column of your sheet, then the 9th column, 8th row, is the cell you want to reference. So, the variable i = last column - 1, in this example.
In this case, the column is always added to the right of column I, the assumed last column in the sheet.
One other assumption is that you're using rows 2 to 100 for the range that you have the formula... So, Range("J2:J100").Formula will be affected by your actual range for the formula.
I am working on setting up a column of cells in Excel and I would like each cell in the column to pull data from multiple columns of cells from another sheet, with each cell having a one-on-one relationship with each other. For instance, I have Column A on Sheet 1 and it is automatically populated from data in Column A and Column B on Sheet 2 (once Column A runs out of data). If any of the data is changed on Sheet 2, the changes will be updated on Sheet 1. If an item is added, it will automatically be inserted on Sheet 1. Is this possible using standard formulas or array formulas, or do I need to use macros or VBA? Any suggestions would be appreciated. Thank you much in advance.
Either
Copy your formula such as IF(ISBLANK(Sheet2!A2),"",Sheet2!A2+Sheet2!B2 down a greater number of rows than you're likely to need.
or
Write a macro to run each that will copy your formula for you.
lr = Sheets("Sheet2").UsedRange.SpecialCells(xlCellTypeLastCell).Row
Sheets("Sheet1").Select
Range("A2").Select
Selection.Copy
Range("A3:A" & lr).Select
ActiveSheet.Paste