I have an Excel file with three sheets with ten columns (A through J).
Sheet1 is a data entry sheet that uses VBA code to transfer a record to the next blank line in Sheet2 where each data entry row is stored. This is working.
Sheet3 is an EDIT sheet to modify a previously-entered record on sheet2.
Using the EDIT sheet, I have VBA code that looks for the matching claim number on sheet2 and clears out the comments.
PROBLEM:
The next time there is a record with comments transferred to sheet2 using the ".End(xlUp)" method it puts that comment on J2 vs. J10 because J1-9 were empty.
QUESTION:
How can I put the comment for claim #10 on J10?
As a workaround I put a dash on each empty line where there are no comments, but that is not an optimal solution as there are many hands that touch that workbook.
In Sheet2 decide on a column that you know will always have a value (Column A for example). Work out the last row number using that column
lastRow = Sheet2.Cells(Rows.Count, "A").End(xlUp).Row + 1
And then use lastRow to update the new comment
Sheet2.Cells(lastRow, "J") = theNewComment
Related
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
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 need to be able to insert the same 5 rows of data between every row on an Excel sheet. The 5 rows are not blank but contain specific data that needs to be repeated. The source of the 5 rows could be on a second sheet or rows 2 through 6 on sheet 1, which ever works best. Copy and pasting manually unfortunately is not an option as there are hundreds of lines. Is anyone able to provide some guidance as to how to accomplish this task?
You can use a formula in your sheet 2 like below:
=INDIRECT("Sheet1!"&ADDRESS(FLOOR(ROW()-1;5)/5+1;1))
By using this formula you will have each rows 5 times dynamically, that as soon as any change on sheet1; data in sheet 2 will be updated.
If you want to make them static Copy your data and Paste them with Values Only option.
You need to use a macro to do this:
Sub PasteRangeEveryNthRow()
Dim RW As Long, i As Long
RW = Range("A" & Rows.Count).End(xlUp).Row
Sheets("Sheet2").Range("A1:A5").Copy
For i = 1 To RW Step 1
Range("A" & i).PasteSpecial Paste:=xlPasteFormulas
Next i
End Sub
This code presupposes that you are copying the range A1:A5 from SHEET2 and pasting it every one line until the last data in the column A.
basically, you need to press ALT+F11 to open the VBA window in excel , then go to INSERT>MODULE and paste this code there. Then run this macro from the developer tab in excel.
if you don't see the developer tab in your excel, go to the options and enable it.
I saw many similar questions on this site but non of them has answer. Not sure why. Probably it is too simple to bother. Not for me though. I am not good at all with VBA and will not probably need to pick on it for another number of years. Hopefully someone will be kind to spend time and help.
I have two sheets in a workbook. Sht1 contains data organized by rows. Rows populated daily, total number of rows will be 300 to 400 by the end of project. Sht2 represents a document form. Most of the cells on that form contain static information that does not change from one report to another. Except some dynamic cells that have to be populated from Sht1. I print the form and file the hard copy. I might come back and print some reports one more time if the hard copies gone missing or the data changed for some reason. The point is clear - I do not want to keep and manage 400 Word files. It is just painful.
What I wanted is assign a code to a command button which will call for an input box. I enter the row ID (I guess the rows should be numbered consequently from 1 to N). Then VBA takes data from some cells of that row, lets say C5 (when ID=4), E5 and H5 on Sht1 and copies them to cells B5, D5 and D7 on Sht2.
Much appreciated for your time reading this and even more if you can help.
Thank you.
Here is some very simple code to copy data from one cell on Sheet1 to another cell on Sheet2.
Sub Macro1()
Dim iRow As Integer
iRow = InputBox("Which row?")
Worksheets("Sht2").Cells(5, 2).Value = Worksheets("Sht1").Cells(iRow, 3).Value
Worksheets("Sht2").Cells(5, 4).Value = Worksheets("Sht1").Cells(iRow, 5).Value
Worksheets("Sht2").Cells(7, 4).Value = Worksheets("Sht1").Cells(iRow, 7).Value
End Sub
This takes values from the row specified on Sheet1, columns C, E, and H.
It copies these values onto Sheet2, cells B5, D5, D7, respectively. Note the order of arguments to Cells(row, col), which is opposite to the Excel cell references that you would be used to. In other words, remember that Cells(1, 3) is actually C1.
This is about as simple as I can make it but it should set you in the right direction.
So I've got this Workbook which contains a lot of data. And I've got this one sheet which basically copies the data based on certain conditions.
Each cell in each row looks like this (the last specified cell is the one where the formula is in):
=IF(Numbers1!E2<>0;Numbers1!A2;"")
=IF(Numbers1!E3<>0;Numbers1!A3;"")
=IF(Numbers1!E4<>0;Numbers1!A4;"")
=IF(Numbers1!E2<>0;Numbers1!B2;"")
=IF(Numbers1!E3<>0;Numbers1!B3;"")
=IF(Numbers1!E4<>0;Numbers1!B4;"")
So the formula in cell A2 is the first one, formula in A3 is the second line etc.
I want to copy the value from the same column and row from the sheet Numbers1, IF the value in the same row of column E is not 0. This seems to be working just fine.
But, when I update the data in Numbers1 sheet, the formulas are all of a sudden invalid and the formula now looks like this:
=IF(Numbers1!#REF!<>0;Numbers1!#REF!;"")
Each formula in each cells look identical to the formula above. And I can't have that, why can't Excel just keep the formula as it is without "helping" me?
Since you may be better off using a macro to rewrite your formulas, here are the basics:
Sub RewriteFormulas()
Dim row, col As Integer
row = 1 'row you want your target formulas to be on
For row = 1 To 60
For col = 1 To 13
ActiveSheet.Cells(row, col).Formula = "=IF(Numbers1!" & Cells(row,col).Address & "<>0,Numbers1!" & Cells(row+2,col).Adddress & ","""")"
Next row
Next col
End Sub
You can play around with using different sheets (or different workbooks) instead of just ActiveSheet so you can have 1 workbook that stores the macro and alters data in whatever workbooks provide your updated datasets.
Hope that helps...