![]() |
Where to put code
Using MSOffice2003
On my spreadsheet, I want to do this: If C15.value 0 then D15.value = 65 Then I want to copy this down these two rows. Where do I put this code, and am I using proper Excel VBA syntax? Thanks for your help. Joanne |
Where to put code
Sub joanne()
For i = 15 To Cells(Rows.Count, "C").End(xlUp).Row If Cells(i, "C").Value 0 Then Cells(i, "D").Value = 65 End If Next End Sub Put this in a standard module -- Gary''s Student - gsnu20076b "Joanne" wrote: Using MSOffice2003 On my spreadsheet, I want to do this: If C15.value 0 then D15.value = 65 Then I want to copy this down these two rows. Where do I put this code, and am I using proper Excel VBA syntax? Thanks for your help. Joanne |
Where to put code
Gary''s Student wrote:
I copied your code into a standard module in my workbook as you instructed, but it does not do the intended deed. As I understand the code, it is creating an index of all cells in col 'c' starting with row 15 to the end of the row - then looking (row by row) to see if the cell in c has a value greater than 0 - if so, then the cell in that row in col 'd' should be equal to 65. Is that right? It seems a simple thing. I don't understand why it doesn't work. I have the cells in question formatted for currency with a leading $ - would that make any difference? What I am trying to do on the spreadsheet is make col D = 65 only in the rows where there will be a value 0 in col C - maybe I am taking the wrong approach altogether? Thanks for your interest in my problem Joanne Sub joanne() For i = 15 To Cells(Rows.Count, "C").End(xlUp).Row If Cells(i, "C").Value 0 Then Cells(i, "D").Value = 65 End If Next End Sub Put this in a standard module |
Where to put code
You probably just need to be sheet specific since it is in a module.
Sub joanne() For i = 15 To Sheets(1).Cells(Rows.Count, "C").End(xlUp).Row If Sheets(1).Cells(i, "C").Value 0 Then Sheets(1).Cells(i, "D").Value = 65 End If Next End Sub change the 1 to your sheet number or name. -- -John Please rate when your question is answered to help us and others know what is helpful. "Joanne" wrote: Gary''s Student wrote: I copied your code into a standard module in my workbook as you instructed, but it does not do the intended deed. As I understand the code, it is creating an index of all cells in col 'c' starting with row 15 to the end of the row - then looking (row by row) to see if the cell in c has a value greater than 0 - if so, then the cell in that row in col 'd' should be equal to 65. Is that right? It seems a simple thing. I don't understand why it doesn't work. I have the cells in question formatted for currency with a leading $ - would that make any difference? What I am trying to do on the spreadsheet is make col D = 65 only in the rows where there will be a value 0 in col C - maybe I am taking the wrong approach altogether? Thanks for your interest in my problem Joanne Sub joanne() For i = 15 To Cells(Rows.Count, "C").End(xlUp).Row If Cells(i, "C").Value 0 Then Cells(i, "D").Value = 65 End If Next End Sub Put this in a standard module |
Where to put code
remove wrote:
That did not help any. Still no value dropped in row on col D. Should I be using the column headers for cols C and D instead of just 'C' and 'D'? The code is in a module, not on the ws or in the wb. This is correct? Sub is named LaborRate, which I believe should be okay. Thanks for your time on this Joanne You probably just need to be sheet specific since it is in a module. Sub joanne() For i = 15 To Sheets(1).Cells(Rows.Count, "C").End(xlUp).Row If Sheets(1).Cells(i, "C").Value 0 Then Sheets(1).Cells(i, "D").Value = 65 End If Next End Sub change the 1 to your sheet number or name. |
All times are GMT +1. The time now is 11:22 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com