I am trying to find the next empty cell in a range, starting from a specific column and then trying to put in todays date.
Code:
ThisWorkbook.ActiveSheet.Cells(ThisWorkbook.ActiveSheet.Rows.Count, "U").End(xlLeft).Offset(0, 1).Value = Now()
My Range to check for blank cells is V to X.
So for instance if i had a spreadsheet that looked like below:
Column U Column V Column W Column X
Start checking blanks from here but don't check this column itself I'm Not a blank Cell so move to the next cell and check I'm a blank cell. Put value here I am a blank cell. I will have a value placed in me next time
At the moment my code is putting the date in the first blank cell in a row starting from column A. This is obviously not correct.
Please can someone show me where I am going wrong?
Change xlleft to xlToLeft
I recommend to used usedrange rows count than simple sheet.rows.count for your requirement.
ThisWorkbook.ActiveSheet.Cells(ActiveSheet.UsedRange.Rows.Count,"U").End(xlToLeft).Offset(0, 1)
Related
I've looked high and low for this and can't find a solution. Plenty with formulas, but it must be in VBA.
I have a range of text in column A (A2:A100) and dates in column B (B2:B100), with sequential calendar dates in row 1 (C1:Z1). For every cell in the matrix/table, if the date in column B is the same as the date in row 1, the text in corresponding column A must be displayed. I can't use a VLOOKUP or MATCH formula, as the columns are narrow and don't display the full text unwrapped because of the formula in the adjacent cell. Thanks for any guidance. In the below, N2 must be "Electrician chasing", since N1 is the same as B2.
I think you want this (and you got your columns A and B the wrong way round)
Sub LoopAndDisplay
Dim r as range
For each r in range("C2:Z200")
If cells(1,r.column) = cells(r.row,2) then 'if date above matches column B then
r = cells(r.row,1) 'display contents of column A
End If
Next R
End Sub
I'm trying to make a worksheet where one column automatically numbers based on the value of another cell.
If the cell in the first column says 'MSG', the value in the next cell, should be something like MSGRA15_00001, if in another row, the first cell is also MSG, the value in the next cell should become MSGRA15_00002.
If the value in the first column says SEL the returned value in the next column should be SELRA15_00001 and so on...
Cell numbering based on previous cell
Can anyone help me on this?
Thanks a lot!
Assuming your MSG/SEL-column is in range A1:A?, you can paste
=A1&"RA15_"&TEXT(COUNTIF(A$1:A1;A1);"00000")
Into B1 and then copy and paste it from there.
I have a column of numeric data, where I need to sum the values from a specified cell, down to the last value before the first blank cell in the Column. I have used a Range function previously to complete this, but on this occasion the number of rows before the blank cell is unknown and cannot be defined in a range. the simple explanation is I need the result in cell A1 to be
=sum (A6:AX)
where X is one before the first blank cell.
I will then write this into my VBA loop to complete it for nth columns over nth sheets.
Use the following sub:
Sub SumTillBlankCell()
Dim BeforeFirstBlankCell
BeforeFirstBlankCell = Range("A6").End(xlDown).Row
Range("A1").Value = Application.Sum(Range("A6:A" & BeforeFirstBlankCell))
End Sub
In Microsoft Excel, I have two columns in a sheet. The first column has values like B2,A13,BB125 and the next column has some number values like 12,569,78.
I want to find the cell from the first column in another sheet and to that cell add the value from the second column.
Does anyone know how to do that?
You can retrieve the value from the cell in column A and pass it to Range() to address the cell in your other sheet.
For example:
' Use A1 as an example...
Dim r As Range
Set r = Range("A1")
' Use A1's value to address a cell on Sheet2 and assign the value from B1...
Sheet2.Range(r.Value).Value = r.Offset(, 1).Value
I have this code:
Sub Button26_Click()
Dim s1, s2
Set s1 = Worksheets("Invoice Generator")
Set s2 = Worksheets("Past Invoices")
With s2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).EntireRow
.Cells(, "a").Value = s1.Range("f27").Value
End With
End Sub
To copy the cell f27 (initially) from sheet one to sheet two (on a new row each time) when the button is clicked. However, if I change "a" to any other cell reference then the data only gets copied once - subsequent clicks do not work.
Anyone have any ideas? Thanks.
You are setting the position by starting at the bottom of column A and looking up to the first non-blank cell then offsetting down one row to a blank cell. If you take this position but stuff values into the row starting at column B, you never fill that empty cell in column A so subsequent calls to the same routine will reposition to exactly the same spot. If you are going to use column B as the target, you need to position the new transfer of values based on the first blank cell in columns B, not column A.
Dim targetCOL as long
targetCOL = 2
With s2.Cells(Rows.Count, targetCOL).End(xlUp).Offset(1, 0).EntireRow
.Cells(, targetCOL).Value = s1.Range("f27").Value
End With
Since you have to change the column of both the positioning method and the target of the values it makes sense to put either the alphabetic columns reference or the numerical column index into a variable so that changing it there will change it in both required places. In the above suggested modification, I've used the column's numerical index to set column B.