ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Where to put code (https://www.excelbanter.com/excel-programming/403411-where-put-code.html)

Joanne

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

Gary''s Student

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


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




John Bundy

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





Joanne

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.




John Bundy

Where to put code
 
The following is exactly what i used, I tried it with a $ in front, storing
as text and anything else i could think of and it worked fine. I wonder, do
you know you have to run this everytime you want 65 to appear? it does not do
this automatically, if you need that let me know. If this code does not work
for you then feel free to send me the sheet and I will see what's going on
first hand. vethis

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
--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"Joanne" wrote:

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